@fern-api/java-dynamic-snippets 3.34.6 → 3.34.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -25,7 +25,7 @@ Value: ${JSON.stringify(t)}
25
25
  Attempted ${r.length} variants:
26
26
  ${u}
27
27
 
28
- This prevents invalid snippet code generation that would cause formatter errors.`)}getUndiscriminatedUnionFieldName({typeReference:e}){switch(e.type){case"list":return this.getUndiscriminatedUnionFieldNameForList({list:e});case"literal":return this.getUndiscriminatedUnionFieldNameForLiteral({literal:e.value});case"map":return this.getUndiscriminatedUnionFieldNameForMap({map:e});case"named":{let t=this.context.resolveNamedType({typeId:e.value});return t==null?void 0:this.context.getClassName(t.declaration.name)}case"optional":return this.getUndiscriminatedUnionFieldNameForOptional({typeReference:e});case"nullable":return this.getUndiscriminatedUnionFieldNameForNullable({typeReference:e});case"primitive":return this.getUndiscriminatedUnionFieldNameForPrimitive({primitive:e.value});case"set":return this.getUndiscriminatedUnionFieldNameForSet({set:e});case"unknown":return"Unknown";default:$(e)}}getUndiscriminatedUnionFieldNameForList({list:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`ListOf${t}`}getUndiscriminatedUnionFieldNameForMap({map:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e.key});if(t==null)return;let r=this.getUndiscriminatedUnionFieldName({typeReference:e.value});if(r!=null)return`MapOf${t}To${r}`}getUndiscriminatedUnionFieldNameForOptional({typeReference:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`Optional${t}`}getUndiscriminatedUnionFieldNameForNullable({typeReference:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`Nullable${t}`}getUndiscriminatedUnionFieldNameForSet({set:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`SetOf${t}`}getUndiscriminatedUnionFieldNameForLiteral({literal:e}){}getUndiscriminatedUnionFieldNameForPrimitive({primitive:e}){switch(e){case"INTEGER":case"UINT":return"Integer";case"LONG":case"UINT_64":return"Long";case"FLOAT":return"Float";case"DOUBLE":return"Double";case"BOOLEAN":return"Boolean";case"BIG_INTEGER":return"BigInteger";case"STRING":return"String";case"UUID":return"Uuid";case"DATE":return"Date";case"DATE_TIME":return"DateTime";case"BASE_64":return"Base64";default:$(e)}}convertUnknown({value:e}){return this.context.customConfig?.["generate-unknown-as-json-node"]===!0?this.convertToJsonNode({value:e}):d.TypeLiteral.unknown(e)}convertToJsonNode({value:e}){let t=d.classReference({name:"ObjectMappers",packageName:this.context.getCorePackageName()});return typeof e=="string"?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.string(e)]})):typeof e=="number"?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.integer(e)]})):typeof e=="boolean"?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.boolean(e)]})):e===null?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.raw(d.codeblock("null"))]})):Array.isArray(e)?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.list({valueType:d.Type.object(),values:e.map(r=>d.TypeLiteral.unknown(r)),isParameter:!0})]})):typeof e=="object"&&e!==null?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.unknown(e)]})):d.TypeLiteral.unknown(e)}convertPrimitive({primitive:e,value:t,as:r}){switch(e){case"INTEGER":case"UINT":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.integer(a)}case"LONG":case"UINT_64":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.long(a)}case"FLOAT":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.float(a)}case"DOUBLE":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.double(a)}case"BOOLEAN":{let a=this.getValueAsBoolean({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.boolean(a)}case"STRING":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.string(a)}case"DATE":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():this.context.customConfig?.["use-local-date-for-dates"]===!0?d.TypeLiteral.date(a):d.TypeLiteral.string(a)}case"DATE_TIME":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.dateTime(a)}case"UUID":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.uuid(a)}case"BASE_64":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.bytes(a)}case"BIG_INTEGER":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.bigInteger(a)}default:$(e)}}getValueAsNumber({value:e,as:t}){let r=t==="mapKey"&&typeof e=="string"?Number(e):e;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:e,as:t}){let r=t==="mapKey"?typeof e=="string"?e==="true":e==="false"?!1:e:e;return this.context.getValueAsBoolean({value:r})}};m();y();h();var ir=class{constructor({context:e}){N(this,"context");this.context=e}convert(e){switch(e.typeReference.type){case"list":return d.Type.list(this.convert({typeReference:e.typeReference}));case"literal":return this.convertLiteral({literal:e.typeReference.value});case"map":return d.Type.map(this.convert({typeReference:e.typeReference.key}),this.convert({typeReference:e.typeReference.value}));case"named":{let t=this.context.resolveNamedType({typeId:e.typeReference.value});return t==null?this.convertUnknown():this.convertNamed({named:t})}case"optional":case"nullable":return d.Type.optional(this.convert({typeReference:e.typeReference.value}));case"primitive":return this.convertPrimitive({primitive:e.typeReference.value});case"set":return d.Type.set(this.convert({typeReference:e.typeReference}));case"unknown":return this.convertUnknown();default:$(e.typeReference)}}convertNamed({named:e}){switch(e.type){case"alias":return this.convert({typeReference:e.typeReference});case"enum":case"discriminatedUnion":case"object":case"undiscriminatedUnion":return d.Type.reference(d.classReference({name:this.context.getClassName(e.declaration.name),packageName:this.context.getTypesPackageName(e.declaration.fernFilepath)}));default:$(e)}}convertLiteral({literal:e}){switch(e.type){case"boolean":return d.Type.boolean();case"string":return d.Type.string()}}convertUnknown(){return this.context.customConfig?.["generate-unknown-as-json-node"]===!0?d.Type.reference(d.classReference({name:"JsonNode",packageName:"com.fasterxml.jackson.databind"})):d.Type.object()}convertPrimitive({primitive:e}){switch(e){case"INTEGER":return d.Type.integer();case"UINT":return d.Type.integer();case"LONG":return d.Type.long();case"UINT_64":return d.Type.long();case"FLOAT":return d.Type.float();case"DOUBLE":return d.Type.double();case"BOOLEAN":return d.Type.boolean();case"STRING":return d.Type.string();case"DATE":return d.Type.date();case"DATE_TIME":return d.Type.dateTime();case"UUID":return d.Type.uuid();case"BASE_64":return d.Type.bytes();case"BIG_INTEGER":return d.Type.bigInteger();default:$(e)}}};m();y();h();var sr=class{constructor({context:e}){N(this,"context");this.context=e}getFilePropertyInfo({body:e,value:t}){let r={fileFields:[],bodyPropertyFields:[]},a=this.context.getRecord(t)??{};for(let o of e.properties)switch(o.type){case"file":r.fileFields.push({name:this.context.getMethodName(o.name),value:this.getSingleFileProperty({property:o,record:a})});break;case"fileArray":r.fileFields.push({name:this.context.getMethodName(o.name),value:this.getArrayFileProperty({property:o,record:a})});break;case"bodyProperty":r.bodyPropertyFields.push({name:this.context.getMethodName(o.name.name),value:this.getBodyProperty({property:o,record:a})});break;default:$(o)}return r}getSingleFileProperty({property:e,record:t}){let r=this.context.getSingleFileValue({property:e,record:t});return r==null?d.TypeLiteral.nop():d.TypeLiteral.reference(this.context.getFileStreamFromString(r))}getArrayFileProperty({property:e,record:t}){let r=this.context.getFileArrayValues({property:e,record:t});if(r==null)return d.TypeLiteral.nop();for(let a of r)return d.TypeLiteral.reference(this.context.getFileStreamFromString(a));return d.TypeLiteral.nop()}getBodyProperty({property:e,record:t}){let r=t[e.name.wireValue];return r==null?d.TypeLiteral.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:r})}};var Il=new Set(["enum","extends","package","void","short","class","abstract","return","import","for","assert","switch"]),El=new Set(["getClass","notify","notifyAll","wait"]),or=class n extends Bt{constructor({ir:t,config:r,options:a}){super({ir:t,config:r,options:a});N(this,"ir");N(this,"customConfig");N(this,"dynamicTypeMapper");N(this,"dynamicTypeLiteralMapper");N(this,"filePropertyMapper");this.ir=t,this.customConfig=Rr.parse(r.customConfig??{}),this.dynamicTypeMapper=new ir({context:this}),this.dynamicTypeLiteralMapper=new ar({context:this}),this.filePropertyMapper=new sr({context:this})}clone(){return new n({ir:this.ir,config:this.config,options:this.options})}getClassName(t){return this.getName(t.pascalCase.safeName)}getEnumName(t){return this.getName(t.screamingSnakeCase.safeName)}getPropertyName(t){return this.getName(t.camelCase.safeName)}getMethodName(t){let r=t.camelCase.safeName;return this.isReservedMethodName(r)?r+"_":this.getName(r)}getRootClientClassReference(){return d.classReference({name:this.getRootClientClassName(),packageName:this.getRootPackageName()})}getRootClientClassName(){return this.customConfig?.["client-class-name"]??`${this.getBaseNamePrefix()}Client`}getEnvironmentClassName(){return"Environment"}getEnvironmentTypeReferenceFromID(t){let r=this.resolveEnvironmentName(t);if(r!=null)return d.codeblock(a=>{a.writeNode(this.getEnvironmentClassReference()),a.write("."),a.write(this.getEnumName(r))})}getEnvironmentClassReference(){return d.classReference({name:this.getEnvironmentClassName(),packageName:this.getCorePackageName()})}getJavaClassReferenceFromDeclaration({declaration:t}){return d.classReference({name:t.name.pascalCase.unsafeName,packageName:this.getTypesPackageName(t.fernFilepath)})}getNullableClassReference(){return d.classReference({name:"Nullable",packageName:this.getCorePackageName()})}getNullableOfNull(){return d.TypeLiteral.reference(d.invokeMethod({on:this.getNullableClassReference(),method:"ofNull",arguments_:[]}))}getOptionalNullableClassReference(){return d.classReference({name:"OptionalNullable",packageName:this.getCorePackageName()})}getOptionalNullableAbsent(){return d.TypeLiteral.reference(d.invokeMethod({on:this.getOptionalNullableClassReference(),method:"absent",arguments_:[]}))}getOptionalNullableOf(t){return d.TypeLiteral.reference(d.invokeMethod({on:this.getOptionalNullableClassReference(),method:"of",arguments_:[t]}))}getFileStreamFromString(t){return d.TypeLiteral.reference(d.codeblock(r=>{r.write("new "),r.writeNode(this.getFileStreamClassReference()),r.write("("),r.writeNode(this.getByteArrayInputStreamClassReference()),r.write("("),r.writeNode(d.TypeLiteral.string(t)),r.write(".getBytes("),r.writeNode(this.getStandardCharsetsClassReference()),r.write(".UTF_8)))")}))}getFileStreamClassReference(){return d.classReference({name:"FileStream",packageName:this.getCorePackageName()})}getByteArrayInputStreamClassReference(){return d.classReference({name:"ByteArrayInputStream",packageName:"java.io"})}getStandardCharsetsClassReference(){return d.classReference({name:"StandardCharsets",packageName:"java.nio.charset"})}isPrimitive(t){switch(t.type){case"primitive":return!0;case"optional":case"nullable":return this.isPrimitive(t.value);case"named":{let r=this.resolveNamedType({typeId:t.value});if(r==null)return!1;switch(r.type){case"alias":return this.isPrimitive(r.typeReference);case"discriminatedUnion":case"undiscriminatedUnion":case"object":case"enum":return!1;default:$(r)}break}case"list":case"set":case"map":case"literal":case"unknown":return!1;default:$(t)}}isDirectLiteral(t){return t.type==="literal"}sortTypeInstancesByRequiredFirst(t,r){let a=new Map;r.forEach((p,g)=>{a.set(p.name.wireValue,g)});let o=[],u=[];for(let p of t)this.isOptional(p.typeReference)?u.push(p):o.push(p);return o.sort((p,g)=>(a.get(p.name.wireValue)??0)-(a.get(g.name.wireValue)??0)),[...o,...u]}associateByWireValue({parameters:t,values:r,ignoreMissingParameters:a}){let o=super.associateByWireValue({parameters:t,values:r,ignoreMissingParameters:a}),u=new Map;for(let g of o)u.set(g.name.wireValue,g);let p=[];for(let g of t){let w=u.get(g.name.wireValue);w!=null&&p.push(w)}return p}getRootPackageName(){let t=this.getPackagePrefixTokens();return this.joinPackageTokens(t)}getCorePackageName(){let t=this.getPackagePrefixTokens();return t.push("core"),this.joinPackageTokens(t)}getTypesPackageName(t){return this.getResourcesPackage(t,"types")}getRequestsPackageName(t){return this.getPackageLayout()==="flat"?this.getTypesPackageName(t):this.getResourcesPackage(t,"requests")}getResourcesPackage(t,r){let a=this.getPackagePrefixTokens();switch(this.getPackageLayout()){case"flat":t!=null&&a.push(...t.packagePath.map(o=>this.getPackageNameSegment(o)));break;case"nested":default:t!=null&&t.allParts.length>0&&a.push("resources"),t!=null&&a.push(...t.allParts.map(o=>this.getPackageNameSegment(o)))}return r!=null&&a.push(r),this.joinPackageTokens(a)}getPackageName(t,r){let a=this.getPackageNameSegments(t);return a=r!=null?[...a,r]:a,[...this.getPackagePrefixTokens(),...a].join(".")}getPackageLayout(){return this.customConfig?.["package-layout"]??"nested"}shouldInlinePathParameters(){return this.customConfig?.["inline-path-parameters"]??!1}shouldInlineFileProperties(){return this.customConfig?.["inline-file-properties"]??!1}getPackageNameSegments(t){return t.packagePath.map(r=>this.getPackageNameSegment(r))}getPackageNameSegment(t){return t.camelCase.safeName.toLowerCase()}getPackagePrefixTokens(){if(this.customConfig?.["package-prefix"]!=null)return this.customConfig["package-prefix"].split(".");let t=[];return t.push("com"),t.push(...this.splitOnNonAlphaNumericChar(this.config.organization)),t.push(...this.splitOnNonAlphaNumericChar(this.getApiName())),t}getBaseNamePrefix(){return this.convertKebabCaseToUpperCamelCase(this.config.organization)+this.convertKebabCaseToUpperCamelCase(this.getApiName())}getApiName(){return xr(this.config.workspaceName)}startsWithNumber(t){return/^\d/.test(t)}splitOnNonAlphaNumericChar(t){return t.split(/[^a-zA-Z0-9]/)}convertKebabCaseToUpperCamelCase(t){return t.replace(/-([a-z])/g,(r,a)=>a.toUpperCase()).replace(/^[a-z]/,r=>r.toUpperCase())}joinPackageTokens(t){return t.map(a=>this.startsWithNumber(a)?"_"+a:a).join(".")}getName(t){return this.isReservedName(t)?"_"+t:t}isReservedName(t){return Il.has(t)}isReservedMethodName(t){return El.has(t)}};m();y();h();var Ii="com.example.usage",Al="Example",Sl="main",Cl="args",Ei="client",Ll={type:"primitive",value:"STRING"};function Bl(n){if(n.type==="optional"&&n.value.type==="list"){let t=n.value.value;if(t.type==="optional")return{type:"optional",value:{type:"list",value:t.value}}}if(n.type==="list"){let e=n.value;if(e.type==="optional")return{type:"list",value:e.value}}return n}var ur=class{constructor({context:e,formatter:t}){N(this,"context");N(this,"formatter");this.context=e,this.formatter=t}async generateSnippet({endpoint:e,request:t,options:r}){let a=this.getConfig(r);return await this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toStringAsync({packageName:a.fullStylePackageName??Ii,customConfig:this.context.customConfig,formatter:this.formatter})}generateSnippetSync({endpoint:e,request:t,options:r}){let a=this.getConfig(r);return this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toString({packageName:a.fullStylePackageName??Ii,customConfig:this.context.customConfig,formatter:this.formatter})}async generateSnippetAst({endpoint:e,request:t,options:r}){throw new Error("Unsupported")}buildCodeBlock({endpoint:e,snippet:t,options:r}){let a=d.codeblock(u=>{u.writeNodeStatement(this.constructClient({endpoint:e,snippet:t})),u.newLine(),u.writeNodeStatement(this.callMethod({endpoint:e,snippet:t}))}),o=this.getStyle(r);switch(o){case Me.Concise:return a;case Me.Full:return this.buildFullCodeBlock({body:a,options:r});default:$(o)}}constructClient({endpoint:e,snippet:t}){let r=e.auth?.type==="oauth";return d.codeblock(a=>{if(a.writeNode(this.context.getRootClientClassReference()),a.write(` ${Ei} = `),r&&t.auth?.type==="oauth"){let o=t.auth;a.writeNode(this.context.getRootClientClassReference()),a.write(`.withCredentials("${o.clientId}", "${o.clientSecret}")`),a.writeNewLineIfLastLineNot(),a.indent();let u=this.getRootClientBuilderArgsExcludingAuth({endpoint:e,snippet:t});for(let p of u)a.write(`.${p.name}(`),p.value.shouldWriteInLine()||a.newLine(),a.writeNode(p.value),p.value.shouldWriteInLine()||a.newLine(),a.writeLine(")");a.writeLine(".build()"),a.dedent()}else a.writeNode(d.TypeLiteral.builder({classReference:this.context.getRootClientClassReference(),parameters:this.getRootClientBuilderArgs({endpoint:e,snippet:t})}))})}getRootClientBuilderArgsExcludingAuth({endpoint:e,snippet:t}){let r=[],a=this.getRootClientBaseUrlArg({baseUrl:t.baseURL,environment:t.environment});a!=null&&r.push(a),this.context.errors.scope(se.Headers),this.context.ir.headers!=null&&t.headers!=null&&r.push(...this.getRootClientHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope();let o=new Set;if([...this.context.ir.pathParameters??[],...e.request.pathParameters??[]].forEach(p=>{p.variable!=null&&o.add(p.variable)}),this.context.ir.variables!=null&&this.context.ir.variables.length>0){for(let p of this.context.ir.variables)if(o.has(p.id)){let g=p.name.camelCase.unsafeName;r.push({name:g,value:d.TypeLiteral.string(`YOUR_${p.name.screamingSnakeCase.unsafeName}`)})}}if(this.context.errors.scope(se.PathParameters),this.context.ir.pathParameters!=null&&this.context.ir.pathParameters.length>0){let p=this.context.ir.pathParameters.filter(g=>g.variable==null);p.length>0&&r.push(...this.getPathParameters({namedParameters:p,snippet:t}))}return this.context.errors.unscope(),r}buildFullCodeBlock({body:e,options:t}){let r=this.getConfig(t),a=d.class_({name:r.fullStyleClassName??Al,access:d.Access.Public}),o=d.parameter({name:Cl,type:d.Type.array(d.Type.string())});return a.addMethod(d.method({name:Sl,access:d.Access.Public,static_:!0,parameters:[o],body:e})),a}getRootClientBuilderArgs({endpoint:e,snippet:t}){let r=[];e.auth!=null&&(t.auth!=null?r.push(...this.getRootClientAuthArgs({auth:e.auth,values:t.auth})):this.context.errors.add({severity:D.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`}));let a=this.getRootClientBaseUrlArg({baseUrl:t.baseURL,environment:t.environment});a!=null&&r.push(a),this.context.errors.scope(se.Headers),this.context.ir.headers!=null&&t.headers!=null&&r.push(...this.getRootClientHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope();let o=new Set;if([...this.context.ir.pathParameters??[],...e.request.pathParameters??[]].forEach(p=>{p.variable!=null&&o.add(p.variable)}),this.context.ir.variables!=null&&this.context.ir.variables.length>0){for(let p of this.context.ir.variables)if(o.has(p.id)){let g=p.name.camelCase.unsafeName;r.push({name:g,value:d.TypeLiteral.string(`YOUR_${p.name.screamingSnakeCase.unsafeName}`)})}}if(this.context.errors.scope(se.PathParameters),this.context.ir.pathParameters!=null&&this.context.ir.pathParameters.length>0){let p=this.context.ir.pathParameters.filter(g=>g.variable==null);p.length>0&&r.push(...this.getPathParameters({namedParameters:p,snippet:t}))}return this.context.errors.unscope(),r}getRootClientBaseUrlArg({baseUrl:e,environment:t}){if(e!=null&&t!=null){this.context.errors.add({severity:D.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(e!=null){if(this.context.ir.environments?.environments.type==="multipleBaseUrls"){this.context.errors.add({severity:D.Critical,message:"The Java SDK doesn't support a baseUrl when multiple URL environments are configured"});return}return{name:"url",value:d.TypeLiteral.string(e)}}if(t!=null){if(this.context.isSingleEnvironmentID(t)){let r=this.context.getEnvironmentTypeReferenceFromID(t);if(r==null){this.context.errors.add({severity:D.Warning,message:`Environment ${JSON.stringify(t)} was not found`});return}return{name:"environment",value:d.TypeLiteral.reference(r)}}if(this.context.isMultiEnvironmentValues(t))return this.context.validateMultiEnvironmentUrlValues(t)?{name:"environment",value:d.TypeLiteral.reference(d.instantiateClass({classReference:this.context.getEnvironmentClassReference(),arguments_:Object.values(t).map(r=>this.context.dynamicTypeLiteralMapper.convert({typeReference:Ll,value:r}))}))}:void 0}}getRootClientAuthArgs({auth:e,values:t}){if(t.type!==e.type)return this.addError(this.context.newAuthMismatchError({auth:e,values:t}).message),[];switch(e.type){case"basic":return t.type==="basic"?this.getRootClientBasicAuthArgs({auth:e,values:t}):[];case"bearer":return t.type==="bearer"?this.getRootClientBearerAuthArgs({auth:e,values:t}):[];case"header":return t.type==="header"?this.getRootClientHeaderAuthArgs({auth:e,values:t}):[];case"oauth":return t.type==="oauth"?this.getRootClientOAuthArgs({auth:e,values:t}):[];case"inferred":return this.addWarning("The Java SDK Generator does not support Inferred auth scheme yet"),[];default:$(e)}}addError(e){this.context.errors.add({severity:D.Critical,message:e})}addWarning(e){this.context.errors.add({severity:D.Warning,message:e})}getRootClientBasicAuthArgs({auth:e,values:t}){return[{name:"credentials",value:d.TypeLiteral.raw(`"${t.username}", "${t.password}"`)}]}getRootClientBearerAuthArgs({auth:e,values:t}){return[{name:this.context.getMethodName(e.token),value:d.TypeLiteral.string(t.token)}]}getRootClientHeaderAuthArgs({auth:e,values:t}){return[{name:this.context.getMethodName(e.header.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:e.header.typeReference,value:t.value})}]}getRootClientOAuthArgs({auth:e,values:t}){return[{name:this.context.getMethodName(e.clientId),value:d.TypeLiteral.string(t.clientId)},{name:this.context.getMethodName(e.clientSecret),value:d.TypeLiteral.string(t.clientSecret)}]}getRootClientHeaderArgs({headers:e,values:t}){let r=[];for(let a of e){let o=this.getRootClientHeaderArg({header:a,value:t.value});o!=null&&r.push({name:this.context.getMethodName(a.name.name),value:o})}return r}getRootClientHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:t});if(!d.TypeLiteral.isNop(r))return r}callMethod({endpoint:e,snippet:t}){return d.invokeMethod({on:d.codeblock(Ei),method:this.getMethod({endpoint:e}),arguments_:this.getMethodArgs({endpoint:e,snippet:t})})}getMethodArgs({endpoint:e,snippet:t}){switch(e.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:e.request,snippet:t});case"body":return this.getMethodArgsForBodyRequest({request:e.request,snippet:t});default:$(e.request)}}getMethodArgsForBodyRequest({request:e,snippet:t}){let r=[];this.context.errors.scope(se.PathParameters);let a=(e.pathParameters??[]).filter(u=>u.variable==null);a.length>0&&r.push(...this.getPathParameters({namedParameters:a,snippet:t}).map(u=>u.value)),this.context.errors.unscope(),this.context.errors.scope(se.RequestBody),e.body!=null&&r.push(this.getBodyRequestArg({body:e.body,value:t.requestBody})),this.context.errors.unscope();let o=this.getRequestOptionsArg({request:e,snippet:t});return o!=null&&r.push(o),r}usesOptionalNullable(){return this.context.customConfig?.["collapse-optional-nullable"]===!0}getBodyRequestArg({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":{if(e.value.type==="optional"){if(t==null)return this.usesOptionalNullable()?this.context.getOptionalNullableAbsent():d.TypeLiteral.reference(d.invokeMethod({on:d.classReference({name:"Optional",packageName:"java.util"}),method:"empty",arguments_:[]}));let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value.value,value:t,as:"request"}),a=r.toString({packageName:"com.example",customConfig:this.context.customConfig});return a.includes("Optional.empty()")||a.includes("OptionalNullable.absent()")?r:this.usesOptionalNullable()?this.context.getOptionalNullableOf(r):d.TypeLiteral.optional({value:r,useOf:!0})}return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t,as:"request"})}default:$(e)}}getBytesBodyRequestArg({value:e}){return e==null?d.TypeLiteral.bytes(""):typeof e!="string"?(this.context.errors.add({severity:D.Critical,message:`Expected bytes value to be a string, got ${typeof e}`}),d.TypeLiteral.nop()):d.TypeLiteral.bytes(e)}getMethodArgsForInlinedRequest({request:e,snippet:t}){let r=[],{inlinePathParameters:a,inlineFileProperties:o}={inlinePathParameters:this.context.shouldInlinePathParameters(),inlineFileProperties:this.context.shouldInlineFileProperties()};this.context.errors.scope(se.PathParameters);let u=[],p=(e.pathParameters??[]).filter(w=>w.variable==null);p.length>0&&u.push(...this.getPathParameters({namedParameters:p,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(se.RequestBody);let g=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})||r.push(...u.map(w=>w.value)),o||r.push(...g.fileFields.map(w=>w.value)),r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})?u:[],filePropertyInfo:g})),r}getFilePropertyInfo({request:e,snippet:t}){return e.body==null||!this.context.isFileUploadRequestBody(e.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:e.body,value:t.requestBody})}getInlinedRequestArg({request:e,snippet:t,pathParameterFields:r,filePropertyInfo:a}){this.context.errors.scope(se.QueryParameters);let u=this.context.associateQueryParametersByWireValue({parameters:e.queryParameters??[],values:t.queryParameters??{}}).filter(C=>!this.context.isDirectLiteral(C.typeReference)),g=this.context.sortTypeInstancesByRequiredFirst(u,e.queryParameters??[]).map(C=>({name:this.context.getMethodName(C.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:Bl(C.typeReference),value:C.value,as:"request"})}));this.context.errors.unscope(),this.context.errors.scope(se.Headers);let E=this.context.associateByWireValue({parameters:e.headers??[],values:t.headers??{}}).filter(C=>!this.context.isDirectLiteral(C.typeReference)),J=this.context.sortTypeInstancesByRequiredFirst(E,e.headers??[]).map(C=>({name:this.context.getMethodName(C.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:C.typeReference,value:C.value,as:"request"})}));this.context.errors.unscope(),this.context.errors.scope(se.RequestBody);let S=e.body!=null?this.getInlinedRequestBodyBuilderParameters({body:e.body,value:t.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),d.TypeLiteral.builder({classReference:d.classReference({name:this.context.getClassName(e.declaration.name),packageName:this.context.getRequestsPackageName(e.declaration.fernFilepath)}),parameters:[...r,...J,...g,...S]})}getRequestOptionsArg({request:e,snippet:t}){let r="headers"in e?e.headers??[]:[];if(r.length===0||Object.keys(t.headers??{}).length===0)return;this.context.errors.scope(se.Headers);let a=this.context.associateByWireValue({parameters:r,values:t.headers??{}});if(this.context.errors.unscope(),a.length===0)return;let o=d.classReference({name:"RequestOptions",packageName:this.context.getCorePackageName()}),u=d.invokeMethod({on:o,method:"builder",arguments_:[]});for(let g of a)u=d.invokeMethod({on:u,method:"addHeader",arguments_:[d.TypeLiteral.string(g.name.wireValue),this.context.dynamicTypeLiteralMapper.convert(g)]});let p=d.invokeMethod({on:u,method:"build",arguments_:[]});return d.TypeLiteral.reference(p)}getInlinedRequestBodyBuilderParameters({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyBuilderParameters({parameters:e.value,value:t});case"referenced":return[this.getReferencedRequestBodyPropertyBuilderParameter({body:e,value:t})];case"fileUpload":return this.getFileUploadRequestBodyBuilderParameters({filePropertyInfo:r});default:$(e)}}getFileUploadRequestBodyBuilderParameters({filePropertyInfo:e}){return this.context.shouldInlineFileProperties()?[...e.fileFields,...e.bodyPropertyFields]:e.bodyPropertyFields}getReferencedRequestBodyPropertyBuilderParameter({body:e,value:t}){return{name:this.context.getMethodName(e.bodyKey),value:this.getReferencedRequestBodyPropertyTypeLiteral({body:e.bodyType,value:t})}}getReferencedRequestBodyPropertyTypeLiteral({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t,as:"request"});default:$(e)}}getInlinedRequestBodyPropertyBuilderParameters({parameters:e,value:t}){let a=this.context.associateByWireValue({parameters:e,values:this.context.getRecord(t)??{}}).filter(u=>!this.context.isDirectLiteral(u.typeReference));return this.context.sortTypeInstancesByRequiredFirst(a,e).map(u=>({name:this.context.getMethodName(u.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:u.typeReference,value:u.value,as:"request"})}))}getPathParameters({namedParameters:e,snippet:t}){let r=[],a=this.context.associateByWireValue({parameters:e,values:t.pathParameters??{}});for(let o of a)r.push({name:this.context.getMethodName(o.name.name),value:this.context.dynamicTypeLiteralMapper.convert(o)});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>`${this.context.getMethodName(t)}()`).join(".")}.${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}getStyle(e){return e.style??this.context.options.style??Me.Full}getConfig(e){return e.config??this.context.options.config??{}}};var lr=class extends St{constructor({ir:e,config:t,options:r={}}){super(new or({ir:e,config:t,options:r}))}async generate(e,t={}){return super.generate(e,t)}generateSync(e,t={}){return super.generateSync(e,t)}async generateSnippetAst(e){return super.generateSnippetAst(e)}createSnippetGenerator(e){return new ur({context:e})}};0&&(module.exports={DynamicSnippetsGenerator});
28
+ This prevents invalid snippet code generation that would cause formatter errors.`)}getUndiscriminatedUnionFieldName({typeReference:e}){switch(e.type){case"list":return this.getUndiscriminatedUnionFieldNameForList({list:e});case"literal":return this.getUndiscriminatedUnionFieldNameForLiteral({literal:e.value});case"map":return this.getUndiscriminatedUnionFieldNameForMap({map:e});case"named":{let t=this.context.resolveNamedType({typeId:e.value});return t==null?void 0:this.context.getClassName(t.declaration.name)}case"optional":return this.getUndiscriminatedUnionFieldNameForOptional({typeReference:e});case"nullable":return this.getUndiscriminatedUnionFieldNameForNullable({typeReference:e});case"primitive":return this.getUndiscriminatedUnionFieldNameForPrimitive({primitive:e.value});case"set":return this.getUndiscriminatedUnionFieldNameForSet({set:e});case"unknown":return"Unknown";default:$(e)}}getUndiscriminatedUnionFieldNameForList({list:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`ListOf${t}`}getUndiscriminatedUnionFieldNameForMap({map:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e.key});if(t==null)return;let r=this.getUndiscriminatedUnionFieldName({typeReference:e.value});if(r!=null)return`MapOf${t}To${r}`}getUndiscriminatedUnionFieldNameForOptional({typeReference:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`Optional${t}`}getUndiscriminatedUnionFieldNameForNullable({typeReference:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`Nullable${t}`}getUndiscriminatedUnionFieldNameForSet({set:e}){let t=this.getUndiscriminatedUnionFieldName({typeReference:e});if(t!=null)return`SetOf${t}`}getUndiscriminatedUnionFieldNameForLiteral({literal:e}){}getUndiscriminatedUnionFieldNameForPrimitive({primitive:e}){switch(e){case"INTEGER":case"UINT":return"Integer";case"LONG":case"UINT_64":return"Long";case"FLOAT":return"Float";case"DOUBLE":return"Double";case"BOOLEAN":return"Boolean";case"BIG_INTEGER":return"BigInteger";case"STRING":return"String";case"UUID":return"Uuid";case"DATE":return"Date";case"DATE_TIME":return"DateTime";case"BASE_64":return"Base64";default:$(e)}}convertUnknown({value:e}){return this.context.customConfig?.["generate-unknown-as-json-node"]===!0?this.convertToJsonNode({value:e}):d.TypeLiteral.unknown(e)}convertToJsonNode({value:e}){let t=d.classReference({name:"ObjectMappers",packageName:this.context.getCorePackageName()});return typeof e=="string"?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.string(e)]})):typeof e=="number"?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.integer(e)]})):typeof e=="boolean"?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.boolean(e)]})):e===null?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.raw(d.codeblock("null"))]})):Array.isArray(e)?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.list({valueType:d.Type.object(),values:e.map(r=>d.TypeLiteral.unknown(r)),isParameter:!0})]})):typeof e=="object"&&e!==null?d.TypeLiteral.reference(d.invokeMethod({on:d.codeblock(r=>{r.writeNode(t),r.write(".JSON_MAPPER")}),method:"valueToTree",arguments_:[d.TypeLiteral.unknown(e)]})):d.TypeLiteral.unknown(e)}convertPrimitive({primitive:e,value:t,as:r}){switch(e){case"INTEGER":case"UINT":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.integer(a)}case"LONG":case"UINT_64":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.long(a)}case"FLOAT":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.float(a)}case"DOUBLE":{let a=this.getValueAsNumber({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.double(a)}case"BOOLEAN":{let a=this.getValueAsBoolean({value:t,as:r});return a==null?d.TypeLiteral.nop():d.TypeLiteral.boolean(a)}case"STRING":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.string(a)}case"DATE":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():this.context.customConfig?.["use-local-date-for-dates"]===!0?d.TypeLiteral.date(a):d.TypeLiteral.string(a)}case"DATE_TIME":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.dateTime(a)}case"UUID":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.uuid(a)}case"BASE_64":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.bytes(a)}case"BIG_INTEGER":{let a=this.context.getValueAsString({value:t});return a==null?d.TypeLiteral.nop():d.TypeLiteral.bigInteger(a)}default:$(e)}}getValueAsNumber({value:e,as:t}){let r=t==="mapKey"&&typeof e=="string"?Number(e):e;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:e,as:t}){let r=t==="mapKey"?typeof e=="string"?e==="true":e==="false"?!1:e:e;return this.context.getValueAsBoolean({value:r})}};m();y();h();var ir=class{constructor({context:e}){N(this,"context");this.context=e}convert(e){switch(e.typeReference.type){case"list":return d.Type.list(this.convert({typeReference:e.typeReference}));case"literal":return this.convertLiteral({literal:e.typeReference.value});case"map":return d.Type.map(this.convert({typeReference:e.typeReference.key}),this.convert({typeReference:e.typeReference.value}));case"named":{let t=this.context.resolveNamedType({typeId:e.typeReference.value});return t==null?this.convertUnknown():this.convertNamed({named:t})}case"optional":case"nullable":return d.Type.optional(this.convert({typeReference:e.typeReference.value}));case"primitive":return this.convertPrimitive({primitive:e.typeReference.value});case"set":return d.Type.set(this.convert({typeReference:e.typeReference}));case"unknown":return this.convertUnknown();default:$(e.typeReference)}}convertNamed({named:e}){switch(e.type){case"alias":return this.convert({typeReference:e.typeReference});case"enum":case"discriminatedUnion":case"object":case"undiscriminatedUnion":return d.Type.reference(d.classReference({name:this.context.getClassName(e.declaration.name),packageName:this.context.getTypesPackageName(e.declaration.fernFilepath)}));default:$(e)}}convertLiteral({literal:e}){switch(e.type){case"boolean":return d.Type.boolean();case"string":return d.Type.string()}}convertUnknown(){return this.context.customConfig?.["generate-unknown-as-json-node"]===!0?d.Type.reference(d.classReference({name:"JsonNode",packageName:"com.fasterxml.jackson.databind"})):d.Type.object()}convertPrimitive({primitive:e}){switch(e){case"INTEGER":return d.Type.integer();case"UINT":return d.Type.integer();case"LONG":return d.Type.long();case"UINT_64":return d.Type.long();case"FLOAT":return d.Type.float();case"DOUBLE":return d.Type.double();case"BOOLEAN":return d.Type.boolean();case"STRING":return d.Type.string();case"DATE":return d.Type.date();case"DATE_TIME":return d.Type.dateTime();case"UUID":return d.Type.uuid();case"BASE_64":return d.Type.bytes();case"BIG_INTEGER":return d.Type.bigInteger();default:$(e)}}};m();y();h();var sr=class{constructor({context:e}){N(this,"context");this.context=e}getFilePropertyInfo({body:e,value:t}){let r={fileFields:[],bodyPropertyFields:[]},a=this.context.getRecord(t)??{};for(let o of e.properties)switch(o.type){case"file":r.fileFields.push({name:this.context.getMethodName(o.name),value:this.getSingleFileProperty({property:o,record:a})});break;case"fileArray":r.fileFields.push({name:this.context.getMethodName(o.name),value:this.getArrayFileProperty({property:o,record:a})});break;case"bodyProperty":r.bodyPropertyFields.push({name:this.context.getMethodName(o.name.name),value:this.getBodyProperty({property:o,record:a})});break;default:$(o)}return r}getSingleFileProperty({property:e,record:t}){let r=this.context.getSingleFileValue({property:e,record:t});return r==null?d.TypeLiteral.nop():d.TypeLiteral.reference(this.context.getFileStreamFromString(r))}getArrayFileProperty({property:e,record:t}){let r=this.context.getFileArrayValues({property:e,record:t});if(r==null)return d.TypeLiteral.nop();for(let a of r)return d.TypeLiteral.reference(this.context.getFileStreamFromString(a));return d.TypeLiteral.nop()}getBodyProperty({property:e,record:t}){let r=t[e.name.wireValue];return r==null?d.TypeLiteral.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:r})}};var Il=new Set(["enum","extends","package","void","short","class","abstract","return","import","for","assert","switch"]),El=new Set(["getClass","notify","notifyAll","wait"]),or=class n extends Bt{constructor({ir:t,config:r,options:a}){super({ir:t,config:r,options:a});N(this,"ir");N(this,"customConfig");N(this,"dynamicTypeMapper");N(this,"dynamicTypeLiteralMapper");N(this,"filePropertyMapper");this.ir=t,this.customConfig=Rr.parse(r.customConfig??{}),this.dynamicTypeMapper=new ir({context:this}),this.dynamicTypeLiteralMapper=new ar({context:this}),this.filePropertyMapper=new sr({context:this})}clone(){return new n({ir:this.ir,config:this.config,options:this.options})}getClassName(t){return this.getName(t.pascalCase.safeName)}getEnumName(t){return this.getName(t.screamingSnakeCase.safeName)}getPropertyName(t){return this.getName(t.camelCase.safeName)}getMethodName(t){let r=t.camelCase.safeName;return this.isReservedMethodName(r)?r+"_":this.getName(r)}getRootClientClassReference(){return d.classReference({name:this.getRootClientClassName(),packageName:this.getRootPackageName()})}getRootClientClassName(){return this.customConfig?.["client-class-name"]??`${this.getBaseNamePrefix()}Client`}getEnvironmentClassName(){return"Environment"}getEnvironmentTypeReferenceFromID(t){let r=this.resolveEnvironmentName(t);if(r!=null)return d.codeblock(a=>{a.writeNode(this.getEnvironmentClassReference()),a.write("."),a.write(this.getEnumName(r))})}getEnvironmentClassReference(){return d.classReference({name:this.getEnvironmentClassName(),packageName:this.getCorePackageName()})}getJavaClassReferenceFromDeclaration({declaration:t}){return d.classReference({name:t.name.pascalCase.unsafeName,packageName:this.getTypesPackageName(t.fernFilepath)})}getNullableClassReference(){return d.classReference({name:"Nullable",packageName:this.getCorePackageName()})}getNullableOfNull(){return d.TypeLiteral.reference(d.invokeMethod({on:this.getNullableClassReference(),method:"ofNull",arguments_:[]}))}getOptionalNullableClassReference(){return d.classReference({name:"OptionalNullable",packageName:this.getCorePackageName()})}getOptionalNullableAbsent(){return d.TypeLiteral.reference(d.invokeMethod({on:this.getOptionalNullableClassReference(),method:"absent",arguments_:[]}))}getOptionalNullableOf(t){return d.TypeLiteral.reference(d.invokeMethod({on:this.getOptionalNullableClassReference(),method:"of",arguments_:[t]}))}getFileStreamFromString(t){return d.TypeLiteral.reference(d.codeblock(r=>{r.write("new "),r.writeNode(this.getFileStreamClassReference()),r.write("("),r.writeNode(this.getByteArrayInputStreamClassReference()),r.write("("),r.writeNode(d.TypeLiteral.string(t)),r.write(".getBytes("),r.writeNode(this.getStandardCharsetsClassReference()),r.write(".UTF_8)))")}))}getFileStreamClassReference(){return d.classReference({name:"FileStream",packageName:this.getCorePackageName()})}getByteArrayInputStreamClassReference(){return d.classReference({name:"ByteArrayInputStream",packageName:"java.io"})}getStandardCharsetsClassReference(){return d.classReference({name:"StandardCharsets",packageName:"java.nio.charset"})}isPrimitive(t){switch(t.type){case"primitive":return!0;case"optional":case"nullable":return this.isPrimitive(t.value);case"named":{let r=this.resolveNamedType({typeId:t.value});if(r==null)return!1;switch(r.type){case"alias":return this.isPrimitive(r.typeReference);case"discriminatedUnion":case"undiscriminatedUnion":case"object":case"enum":return!1;default:$(r)}break}case"list":case"set":case"map":case"literal":case"unknown":return!1;default:$(t)}}isDirectLiteral(t){return t.type==="literal"}sortTypeInstancesByRequiredFirst(t,r){let a=new Map;r.forEach((p,g)=>{a.set(p.name.wireValue,g)});let o=[],u=[];for(let p of t)this.isOptional(p.typeReference)?u.push(p):o.push(p);return o.sort((p,g)=>(a.get(p.name.wireValue)??0)-(a.get(g.name.wireValue)??0)),[...o,...u]}associateByWireValue({parameters:t,values:r,ignoreMissingParameters:a}){let o=super.associateByWireValue({parameters:t,values:r,ignoreMissingParameters:a}),u=new Map;for(let g of o)u.set(g.name.wireValue,g);let p=[];for(let g of t){let w=u.get(g.name.wireValue);w!=null&&p.push(w)}return p}getRootPackageName(){let t=this.getPackagePrefixTokens();return this.joinPackageTokens(t)}getCorePackageName(){let t=this.getPackagePrefixTokens();return t.push("core"),this.joinPackageTokens(t)}getTypesPackageName(t){return this.getResourcesPackage(t,"types")}getRequestsPackageName(t){return this.getPackageLayout()==="flat"?this.getTypesPackageName(t):this.getResourcesPackage(t,"requests")}getResourcesPackage(t,r){let a=this.getPackagePrefixTokens();return this.getPackageLayout()==="flat"?t!=null&&a.push(...t.packagePath.map(o=>this.getPackageNameSegment(o))):(t!=null&&t.allParts.length>0&&a.push("resources"),t!=null&&a.push(...t.allParts.map(o=>this.getPackageNameSegment(o)))),r!=null&&a.push(r),this.joinPackageTokens(a)}getPackageName(t,r){let a=this.getPackageNameSegments(t);return a=r!=null?[...a,r]:a,[...this.getPackagePrefixTokens(),...a].join(".")}getPackageLayout(){return this.customConfig?.["package-layout"]??"nested"}shouldInlinePathParameters(){return this.customConfig?.["inline-path-parameters"]??!1}shouldInlineFileProperties(){return this.customConfig?.["inline-file-properties"]??!1}getPackageNameSegments(t){return t.packagePath.map(r=>this.getPackageNameSegment(r))}getPackageNameSegment(t){return t.camelCase.safeName.toLowerCase()}getPackagePrefixTokens(){if(this.customConfig?.["package-prefix"]!=null)return this.customConfig["package-prefix"].split(".");let t=[];return t.push("com"),t.push(...this.splitOnNonAlphaNumericChar(this.config.organization)),t.push(...this.splitOnNonAlphaNumericChar(this.getApiName())),t}getBaseNamePrefix(){return this.convertKebabCaseToUpperCamelCase(this.config.organization)+this.convertKebabCaseToUpperCamelCase(this.getApiName())}getApiName(){return xr(this.config.workspaceName)}startsWithNumber(t){return/^\d/.test(t)}splitOnNonAlphaNumericChar(t){return t.split(/[^a-zA-Z0-9]/)}convertKebabCaseToUpperCamelCase(t){return t.replace(/-([a-z])/g,(r,a)=>a.toUpperCase()).replace(/^[a-z]/,r=>r.toUpperCase())}joinPackageTokens(t){return t.map(a=>this.startsWithNumber(a)?"_"+a:a).join(".")}getName(t){return this.isReservedName(t)?"_"+t:t}isReservedName(t){return Il.has(t)}isReservedMethodName(t){return El.has(t)}};m();y();h();var Ii="com.example.usage",Al="Example",Sl="main",Cl="args",Ei="client",Ll={type:"primitive",value:"STRING"};function Bl(n){if(n.type==="optional"&&n.value.type==="list"){let t=n.value.value;if(t.type==="optional")return{type:"optional",value:{type:"list",value:t.value}}}if(n.type==="list"){let e=n.value;if(e.type==="optional")return{type:"list",value:e.value}}return n}var ur=class{constructor({context:e,formatter:t}){N(this,"context");N(this,"formatter");this.context=e,this.formatter=t}async generateSnippet({endpoint:e,request:t,options:r}){let a=this.getConfig(r);return await this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toStringAsync({packageName:a.fullStylePackageName??Ii,customConfig:this.context.customConfig,formatter:this.formatter})}generateSnippetSync({endpoint:e,request:t,options:r}){let a=this.getConfig(r);return this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toString({packageName:a.fullStylePackageName??Ii,customConfig:this.context.customConfig,formatter:this.formatter})}async generateSnippetAst({endpoint:e,request:t,options:r}){throw new Error("Unsupported")}buildCodeBlock({endpoint:e,snippet:t,options:r}){let a=d.codeblock(u=>{u.writeNodeStatement(this.constructClient({endpoint:e,snippet:t})),u.newLine(),u.writeNodeStatement(this.callMethod({endpoint:e,snippet:t}))}),o=this.getStyle(r);switch(o){case Me.Concise:return a;case Me.Full:return this.buildFullCodeBlock({body:a,options:r});default:$(o)}}constructClient({endpoint:e,snippet:t}){let r=e.auth?.type==="oauth";return d.codeblock(a=>{if(a.writeNode(this.context.getRootClientClassReference()),a.write(` ${Ei} = `),r&&t.auth?.type==="oauth"){let o=t.auth;a.writeNode(this.context.getRootClientClassReference()),a.write(`.withCredentials("${o.clientId}", "${o.clientSecret}")`),a.writeNewLineIfLastLineNot(),a.indent();let u=this.getRootClientBuilderArgsExcludingAuth({endpoint:e,snippet:t});for(let p of u)a.write(`.${p.name}(`),p.value.shouldWriteInLine()||a.newLine(),a.writeNode(p.value),p.value.shouldWriteInLine()||a.newLine(),a.writeLine(")");a.writeLine(".build()"),a.dedent()}else a.writeNode(d.TypeLiteral.builder({classReference:this.context.getRootClientClassReference(),parameters:this.getRootClientBuilderArgs({endpoint:e,snippet:t})}))})}getRootClientBuilderArgsExcludingAuth({endpoint:e,snippet:t}){let r=[],a=this.getRootClientBaseUrlArg({baseUrl:t.baseURL,environment:t.environment});a!=null&&r.push(a),this.context.errors.scope(se.Headers),this.context.ir.headers!=null&&t.headers!=null&&r.push(...this.getRootClientHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope();let o=new Set;if([...this.context.ir.pathParameters??[],...e.request.pathParameters??[]].forEach(p=>{p.variable!=null&&o.add(p.variable)}),this.context.ir.variables!=null&&this.context.ir.variables.length>0){for(let p of this.context.ir.variables)if(o.has(p.id)){let g=p.name.camelCase.unsafeName;r.push({name:g,value:d.TypeLiteral.string(`YOUR_${p.name.screamingSnakeCase.unsafeName}`)})}}if(this.context.errors.scope(se.PathParameters),this.context.ir.pathParameters!=null&&this.context.ir.pathParameters.length>0){let p=this.context.ir.pathParameters.filter(g=>g.variable==null);p.length>0&&r.push(...this.getPathParameters({namedParameters:p,snippet:t}))}return this.context.errors.unscope(),r}buildFullCodeBlock({body:e,options:t}){let r=this.getConfig(t),a=d.class_({name:r.fullStyleClassName??Al,access:d.Access.Public}),o=d.parameter({name:Cl,type:d.Type.array(d.Type.string())});return a.addMethod(d.method({name:Sl,access:d.Access.Public,static_:!0,parameters:[o],body:e})),a}getRootClientBuilderArgs({endpoint:e,snippet:t}){let r=[];e.auth!=null&&(t.auth!=null?r.push(...this.getRootClientAuthArgs({auth:e.auth,values:t.auth})):this.context.errors.add({severity:D.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`}));let a=this.getRootClientBaseUrlArg({baseUrl:t.baseURL,environment:t.environment});a!=null&&r.push(a),this.context.errors.scope(se.Headers),this.context.ir.headers!=null&&t.headers!=null&&r.push(...this.getRootClientHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope();let o=new Set;if([...this.context.ir.pathParameters??[],...e.request.pathParameters??[]].forEach(p=>{p.variable!=null&&o.add(p.variable)}),this.context.ir.variables!=null&&this.context.ir.variables.length>0){for(let p of this.context.ir.variables)if(o.has(p.id)){let g=p.name.camelCase.unsafeName;r.push({name:g,value:d.TypeLiteral.string(`YOUR_${p.name.screamingSnakeCase.unsafeName}`)})}}if(this.context.errors.scope(se.PathParameters),this.context.ir.pathParameters!=null&&this.context.ir.pathParameters.length>0){let p=this.context.ir.pathParameters.filter(g=>g.variable==null);p.length>0&&r.push(...this.getPathParameters({namedParameters:p,snippet:t}))}return this.context.errors.unscope(),r}getRootClientBaseUrlArg({baseUrl:e,environment:t}){if(e!=null&&t!=null){this.context.errors.add({severity:D.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(e!=null){if(this.context.ir.environments?.environments.type==="multipleBaseUrls"){this.context.errors.add({severity:D.Critical,message:"The Java SDK doesn't support a baseUrl when multiple URL environments are configured"});return}return{name:"url",value:d.TypeLiteral.string(e)}}if(t!=null){if(this.context.isSingleEnvironmentID(t)){let r=this.context.getEnvironmentTypeReferenceFromID(t);if(r==null){this.context.errors.add({severity:D.Warning,message:`Environment ${JSON.stringify(t)} was not found`});return}return{name:"environment",value:d.TypeLiteral.reference(r)}}if(this.context.isMultiEnvironmentValues(t))return this.context.validateMultiEnvironmentUrlValues(t)?{name:"environment",value:d.TypeLiteral.reference(d.instantiateClass({classReference:this.context.getEnvironmentClassReference(),arguments_:Object.values(t).map(r=>this.context.dynamicTypeLiteralMapper.convert({typeReference:Ll,value:r}))}))}:void 0}}getRootClientAuthArgs({auth:e,values:t}){if(t.type!==e.type)return this.addError(this.context.newAuthMismatchError({auth:e,values:t}).message),[];switch(e.type){case"basic":return t.type==="basic"?this.getRootClientBasicAuthArgs({auth:e,values:t}):[];case"bearer":return t.type==="bearer"?this.getRootClientBearerAuthArgs({auth:e,values:t}):[];case"header":return t.type==="header"?this.getRootClientHeaderAuthArgs({auth:e,values:t}):[];case"oauth":return t.type==="oauth"?this.getRootClientOAuthArgs({auth:e,values:t}):[];case"inferred":return this.addWarning("The Java SDK Generator does not support Inferred auth scheme yet"),[];default:$(e)}}addError(e){this.context.errors.add({severity:D.Critical,message:e})}addWarning(e){this.context.errors.add({severity:D.Warning,message:e})}getRootClientBasicAuthArgs({auth:e,values:t}){return[{name:"credentials",value:d.TypeLiteral.raw(`"${t.username}", "${t.password}"`)}]}getRootClientBearerAuthArgs({auth:e,values:t}){return[{name:this.context.getMethodName(e.token),value:d.TypeLiteral.string(t.token)}]}getRootClientHeaderAuthArgs({auth:e,values:t}){return[{name:this.context.getMethodName(e.header.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:e.header.typeReference,value:t.value})}]}getRootClientOAuthArgs({auth:e,values:t}){return[{name:this.context.getMethodName(e.clientId),value:d.TypeLiteral.string(t.clientId)},{name:this.context.getMethodName(e.clientSecret),value:d.TypeLiteral.string(t.clientSecret)}]}getRootClientHeaderArgs({headers:e,values:t}){let r=[];for(let a of e){let o=this.getRootClientHeaderArg({header:a,value:t.value});o!=null&&r.push({name:this.context.getMethodName(a.name.name),value:o})}return r}getRootClientHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:t});if(!d.TypeLiteral.isNop(r))return r}callMethod({endpoint:e,snippet:t}){return d.invokeMethod({on:d.codeblock(Ei),method:this.getMethod({endpoint:e}),arguments_:this.getMethodArgs({endpoint:e,snippet:t})})}getMethodArgs({endpoint:e,snippet:t}){switch(e.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:e.request,snippet:t});case"body":return this.getMethodArgsForBodyRequest({request:e.request,snippet:t});default:$(e.request)}}getMethodArgsForBodyRequest({request:e,snippet:t}){let r=[];this.context.errors.scope(se.PathParameters);let a=(e.pathParameters??[]).filter(u=>u.variable==null);a.length>0&&r.push(...this.getPathParameters({namedParameters:a,snippet:t}).map(u=>u.value)),this.context.errors.unscope(),this.context.errors.scope(se.RequestBody),e.body!=null&&r.push(this.getBodyRequestArg({body:e.body,value:t.requestBody})),this.context.errors.unscope();let o=this.getRequestOptionsArg({request:e,snippet:t});return o!=null&&r.push(o),r}usesOptionalNullable(){return this.context.customConfig?.["collapse-optional-nullable"]===!0}getBodyRequestArg({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":{if(e.value.type==="optional"){if(t==null)return this.usesOptionalNullable()?this.context.getOptionalNullableAbsent():d.TypeLiteral.reference(d.invokeMethod({on:d.classReference({name:"Optional",packageName:"java.util"}),method:"empty",arguments_:[]}));let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value.value,value:t,as:"request"}),a=r.toString({packageName:"com.example",customConfig:this.context.customConfig});return a.includes("Optional.empty()")||a.includes("OptionalNullable.absent()")?r:this.usesOptionalNullable()?this.context.getOptionalNullableOf(r):d.TypeLiteral.optional({value:r,useOf:!0})}return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t,as:"request"})}default:$(e)}}getBytesBodyRequestArg({value:e}){return e==null?d.TypeLiteral.bytes(""):typeof e!="string"?(this.context.errors.add({severity:D.Critical,message:`Expected bytes value to be a string, got ${typeof e}`}),d.TypeLiteral.nop()):d.TypeLiteral.bytes(e)}getMethodArgsForInlinedRequest({request:e,snippet:t}){let r=[],{inlinePathParameters:a,inlineFileProperties:o}={inlinePathParameters:this.context.shouldInlinePathParameters(),inlineFileProperties:this.context.shouldInlineFileProperties()};this.context.errors.scope(se.PathParameters);let u=[],p=(e.pathParameters??[]).filter(w=>w.variable==null);p.length>0&&u.push(...this.getPathParameters({namedParameters:p,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(se.RequestBody);let g=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})||r.push(...u.map(w=>w.value)),o||r.push(...g.fileFields.map(w=>w.value)),r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})?u:[],filePropertyInfo:g})),r}getFilePropertyInfo({request:e,snippet:t}){return e.body==null||!this.context.isFileUploadRequestBody(e.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:e.body,value:t.requestBody})}getInlinedRequestArg({request:e,snippet:t,pathParameterFields:r,filePropertyInfo:a}){this.context.errors.scope(se.QueryParameters);let u=this.context.associateQueryParametersByWireValue({parameters:e.queryParameters??[],values:t.queryParameters??{}}).filter(C=>!this.context.isDirectLiteral(C.typeReference)),g=this.context.sortTypeInstancesByRequiredFirst(u,e.queryParameters??[]).map(C=>({name:this.context.getMethodName(C.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:Bl(C.typeReference),value:C.value,as:"request"})}));this.context.errors.unscope(),this.context.errors.scope(se.Headers);let E=this.context.associateByWireValue({parameters:e.headers??[],values:t.headers??{}}).filter(C=>!this.context.isDirectLiteral(C.typeReference)),J=this.context.sortTypeInstancesByRequiredFirst(E,e.headers??[]).map(C=>({name:this.context.getMethodName(C.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:C.typeReference,value:C.value,as:"request"})}));this.context.errors.unscope(),this.context.errors.scope(se.RequestBody);let S=e.body!=null?this.getInlinedRequestBodyBuilderParameters({body:e.body,value:t.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),d.TypeLiteral.builder({classReference:d.classReference({name:this.context.getClassName(e.declaration.name),packageName:this.context.getRequestsPackageName(e.declaration.fernFilepath)}),parameters:[...r,...J,...g,...S]})}getRequestOptionsArg({request:e,snippet:t}){let r="headers"in e?e.headers??[]:[];if(r.length===0||Object.keys(t.headers??{}).length===0)return;this.context.errors.scope(se.Headers);let a=this.context.associateByWireValue({parameters:r,values:t.headers??{}});if(this.context.errors.unscope(),a.length===0)return;let o=d.classReference({name:"RequestOptions",packageName:this.context.getCorePackageName()}),u=d.invokeMethod({on:o,method:"builder",arguments_:[]});for(let g of a)u=d.invokeMethod({on:u,method:"addHeader",arguments_:[d.TypeLiteral.string(g.name.wireValue),this.context.dynamicTypeLiteralMapper.convert(g)]});let p=d.invokeMethod({on:u,method:"build",arguments_:[]});return d.TypeLiteral.reference(p)}getInlinedRequestBodyBuilderParameters({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyBuilderParameters({parameters:e.value,value:t});case"referenced":return[this.getReferencedRequestBodyPropertyBuilderParameter({body:e,value:t})];case"fileUpload":return this.getFileUploadRequestBodyBuilderParameters({filePropertyInfo:r});default:$(e)}}getFileUploadRequestBodyBuilderParameters({filePropertyInfo:e}){return this.context.shouldInlineFileProperties()?[...e.fileFields,...e.bodyPropertyFields]:e.bodyPropertyFields}getReferencedRequestBodyPropertyBuilderParameter({body:e,value:t}){return{name:this.context.getMethodName(e.bodyKey),value:this.getReferencedRequestBodyPropertyTypeLiteral({body:e.bodyType,value:t})}}getReferencedRequestBodyPropertyTypeLiteral({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t,as:"request"});default:$(e)}}getInlinedRequestBodyPropertyBuilderParameters({parameters:e,value:t}){let a=this.context.associateByWireValue({parameters:e,values:this.context.getRecord(t)??{}}).filter(u=>!this.context.isDirectLiteral(u.typeReference));return this.context.sortTypeInstancesByRequiredFirst(a,e).map(u=>({name:this.context.getMethodName(u.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:u.typeReference,value:u.value,as:"request"})}))}getPathParameters({namedParameters:e,snippet:t}){let r=[],a=this.context.associateByWireValue({parameters:e,values:t.pathParameters??{}});for(let o of a)r.push({name:this.context.getMethodName(o.name.name),value:this.context.dynamicTypeLiteralMapper.convert(o)});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>`${this.context.getMethodName(t)}()`).join(".")}.${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}getStyle(e){return e.style??this.context.options.style??Me.Full}getConfig(e){return e.config??this.context.options.config??{}}};var lr=class extends St{constructor({ir:e,config:t,options:r={}}){super(new or({ir:e,config:t,options:r}))}async generate(e,t={}){return super.generate(e,t)}generateSync(e,t={}){return super.generateSync(e,t)}async generateSnippetAst(e){return super.generateSnippetAst(e)}createSnippetGenerator(e){return new ur({context:e})}};0&&(module.exports={DynamicSnippetsGenerator});
29
29
  /*! Bundled license information:
30
30
 
31
31
  @jspm/core/nodelibs/browser/chunk-DtuTasat.js: