diff --git a/config.json b/config.json new file mode 100644 index 000000000..c555d6994 --- /dev/null +++ b/config.json @@ -0,0 +1,11 @@ +{ + "typeMapping": { + "abc": "CustomType", + "string": "String", + "array": "List", + "map": "HashMap" + }, + "importMapping": { + "CustomType": "com.example.custom.CustomType" + } +} \ No newline at end of file diff --git a/examples/spec/twilio_api_v2010.yaml b/examples/spec/twilio_api_v2010.yaml index b51e6a5ab..b5982e4be 100644 --- a/examples/spec/twilio_api_v2010.yaml +++ b/examples/spec/twilio_api_v2010.yaml @@ -1,19 +1,25 @@ components: schemas: - account_enum_X_Twilio_Webhook_Enabled: - type: string - enum: - - 'true' - - 'false' - test_enum_status: - enum: - - in-progress - - paused - - stopped - - processing - - completed - - absent + quickReplyActions: + type: array + items: + $ref: "#/components/schemas/quickReplyAction" + quickReplyActionType: type: string + enum: [ "QUICK_REPLY" ] + quickReplyAction: + type: object + additionalProperties: false + properties: + type: + $ref: "#/components/schemas/quickReplyActionType" + title: + type: string + id: + type: string + required: + - type + - title test.response_object: properties: account_sid: @@ -23,112 +29,7 @@ components: sid: nullable: true type: string - test_string: - nullable: true - type: string - test_integer: - nullable: true - type: integer - test_object: - nullable: true - format: phone-number-capabilities - properties: - fax: - type: boolean - mms: - type: boolean - sms: - type: boolean - voice: - type: boolean - type: object - test_date_time: - format: date-time-rfc-2822 - nullable: true - type: string - example: "Thu, 01 Sep 2016 10:11:12.123456 -0500" - test_number: - nullable: true - type: number - from: - nullable: true - type: string - format: phone-number - price_unit: - nullable: true - format: currency - type: string - example: "USD" - test_number_float: - nullable: true - type: number - format: float - test_number_decimal: - nullable: true - type: decimal - test_enum: - $ref: '#/components/schemas/test_enum_status' - nullable: true - type: string - a2p_profile_bundle_sid: - type: string - minLength: 34 - maxLength: 34 - pattern: ^BU[0-9a-fA-F]{32}$ - nullable: true - description: A2P Messaging Profile Bundle BundleSid - test_array_of_integers: - items: - type: integer - type: array - test_array_of_array_of_integers: - type: array - items: - type: array - items: - type: integer - test_array_of_objects: - items: - format: feedback-issue - properties: - count: - type: number - description: - type: string - type: object - nullable: true - type: array - test_array_of_enum: - description: Permissions authorized to the app - items: - $ref: '#/components/schemas/test_enum_status' - type: string - nullable: true - type: array type: object - test.fetch_response_object: - allOf: - - $ref: '#/components/schemas/test.response_object' - - properties: - status: - type: string - description: The status of the user - message: - type: string - description: A message describing the status of the user - examples: - test.response_object.example: - value: - sid: "CR12345678123456781234567812345678" - test_string: "Ahoy" - test_object: - fax: false - mms: false - sms: true - voice: true - test_number_float: 100.22 - test_enum: "completed" - a2p_profile_bundle_sid: "BU0987654321abcdefABCDEFABCDEFABCD" securitySchemes: accountSid_authToken: scheme: basic @@ -149,122 +50,31 @@ openapi: 3.0.1 paths: /2010-04-01/Accounts.json: description: A top-level resource - get: - description: This operation's summary has a special character - operationId: ListAccount - tags: - - TagThatShouldBeRemoved - parameters: - - in: query - name: DateCreated - schema: - format: date-time - type: string - - in: query - name: Date.Test - schema: - format: date - type: string - - in: query - name: DateCreated< - schema: - format: date-time - type: string - - in: query - name: DateCreated> - schema: - format: date-time - type: string - - in: query - name: PageSize - schema: - maximum: 1000 - minimum: 1 - type: integer - - name: Page - in: query - description: The page index. This value is simply for client state. - schema: - type: integer - minimum: 0 - - name: PageToken - in: query - description: The page token. This is provided by the API. - schema: - type: string - responses: - '200': - content: - application/json: - schema: - properties: - end: - type: integer - first_page_uri: - format: uri - type: string - next_page_uri: - format: uri - type: string - page: - type: integer - page_size: - type: integer - previous_page_uri: - format: uri - type: string - accounts: - items: - $ref: '#/components/schemas/test.response_object' - type: array - start: - type: integer - uri: - format: uri - type: string - title: ListAccountResponse - type: object - examples: - account_response: - summary: Example of Call Recordings - value: - end: 5 - first_page_uri: http://example.com/page1 - next_page_uri: http://example.com/page2 - page: 1 - page_size: 4 - previous_page_uri: http://example.com/page0 - accounts: - - test_string: Ahoy - - test_string: Matey - start: 0 - uri: http://example.com - description: OK - security: - - accountSid_authToken: [ ] post: operationId: CreateAccount - parameters: - - in: header - name: X-Twilio-Webhook-Enabled - schema: - type: string - $ref: '#/components/schemas/account_enum_X_Twilio_Webhook_Enabled' requestBody: content: - application/x-www-form-urlencoded: + application/json: schema: properties: RecordingStatusCallback: - format: uri type: string + format: abc RecordingStatusCallbackEvent: items: type: string + format: abc type: array - Twiml: - type: string - format: twiml + twilioQuickReply: + type: object + description: twilio/quick-reply templates let recipients tap, rather than type, to respond to the message. + nullable: true + additionalProperties: false + properties: + body: + type: string + actions: + $ref: "#/components/schemas/quickReplyActions" title: CreateAccountRequest type: object responses: @@ -292,321 +102,3 @@ paths: mapping: account_sid: sid resource_url: /Accounts/{account_sid}/Applications.json - /2010-04-01/Accounts/{Sid}.json: - description: A top-level resource instance - delete: - operationId: DeleteAccount - parameters: - - in: path - name: Sid - required: true - schema: - maxLength: 34 - minLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - type: string - responses: - '204': - description: The resource was deleted successfully. - security: - - accountSid_authToken: [ ] - get: - operationId: FetchAccount - parameters: - - in: path - name: Sid - required: true - schema: - maxLength: 34 - minLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/test.fetch_response_object' - description: OK - security: - - accountSid_authToken: [ ] - post: - operationId: UpdateAccount - parameters: - - in: path - name: Sid - required: true - schema: - maxLength: 34 - minLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - type: string - requestBody: - content: - application/x-www-form-urlencoded: - schema: - properties: - PauseBehavior: - type: string - Status: - $ref: '#/components/schemas/test_enum_status' - type: string - required: - - Status - title: UpdateAccountRequest - type: object - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/test.response_object' - description: OK - security: - - accountSid_authToken: [ ] - servers: - - url: https://api.twilio.com - x-twilio: - pathType: instance - /2010-04-01/Accounts/{AccountSid}/Calls.json: - description: A nested resource, dose not support listing - post: - operationId: CreateCall - parameters: - - in: path - name: AccountSid - required: true - schema: - maxLength: 34 - minLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - type: string - requestBody: - content: - application/x-www-form-urlencoded: - schema: - properties: - RequiredStringProperty: - type: string - TestArrayOfStrings: - items: - type: string - type: array - TestArrayOfUri: - items: - format: uri - type: string - type: array - TestMethod: - type: string - format: http-method - enum: - - HEAD - - GET - - POST - - PATCH - - PUT - - DELETE - description: 'The HTTP method that we should use to request the - `TestArrayOfUri`.' - required: - - RequiredStringProperty - - TestMethod - title: CreateCallRequest - type: object - responses: - '201': - content: - application/json: - schema: - $ref: '#/components/schemas/test.response_object' - examples: - example: - $ref: '#/components/examples/test.response_object.example' - description: Created - security: - - accountSid_authToken: [ ] - servers: - - url: https://api.twilio.com - x-twilio: - parent: /Accounts/{Sid}.json - dependentProperties: - address: - mapping: - account_sid: account_sid - test_call_sid: sid - resource_url: Accounts/{account_sid}/Addresses/{test_call_sid}/Test.json - pathType: list - /2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json: - description: A nested resource instance that cannot be updated - delete: - operationId: DeleteCall - parameters: - - in: path - name: AccountSid - required: true - schema: - maxLength: 34 - minLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - type: string - - description: INTEGER ID param!!! - in: path - name: TestInteger - required: true - schema: - type: integer - responses: - '204': - description: The resource was deleted successfully. - security: - - accountSid_authToken: [ ] - get: - operationId: FetchCall - parameters: - - in: path - name: AccountSid - required: true - schema: - maxLength: 34 - minLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - type: string - - description: INTEGER ID param!!! - in: path - name: TestInteger - required: true - schema: - type: integer - responses: - '307': - description: Test that an operation with no 2XX responses is handled properly - content: - application/json: - schema: - $ref: '#/components/schemas/test.response_object' - examples: - example: - $ref: '#/components/examples/test.response_object.example' - security: - - accountSid_authToken: [ ] - servers: - - url: https://api.twilio.com - x-twilio: - parent: /Accounts/{Sid}.json - - pathType: instance - /2010-04-01/Accounts/{AccountSid}/Calls/Feedback/Summary.json: - description: A nested resource with sub-dirs and without operations - servers: - - url: https://api.twilio.com - x-twilio: - className: feedback_call_summary - mountName: feedback_call_summary - parent: /Accounts/{AccountSid}/Calls.json - pathType: list - /2010-04-01/Accounts/{AccountSid}/Calls/Feedback/Summary/{Sid}.json: - description: A resource that can only be updated and which has a parent path that needs resolution - post: - operationId: UpdateCallFeedbackSummary - parameters: - - in: path - name: AccountSid - required: true - schema: - maxLength: 34 - minLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - type: string - - in: path - name: Sid - required: true - schema: - type: string - requestBody: - content: - application/x-www-form-urlencoded: - schema: - properties: - AccountSid: - type: string - minLength: 34 - maxLength: 34 - pattern: ^AC[0-9a-fA-F]{32}$ - EndDate: - format: date - type: string - StartDate: - format: date - type: string - required: - - StartDate - - EndDate - title: UpdateCallFeedbackSummaryRequest - type: object - responses: - '201': - content: - application/json: - schema: - $ref: '#/components/schemas/test.response_object' - examples: - custom_type_response_example: - summary: Example of a Feedback Summary - value: - test_array_of_objects: - - count: 4 - description: issue description - description: Created - security: - - accountSid_authToken: [ ] - servers: - - url: https://api.twilio.com - x-twilio: - className: feedback_call_summary - mountName: feedback_call_summary - parent: /Accounts/{AccountSid}/Calls/{TestInteger}.json - pathType: instance - /healthcheck: - x-twilio: - className: healthCheck - libraryVisibility: private - docs_visibility: private - pathType: list - x-skip-path: 'true' - servers: - - url: https://api.twilio.com - description: lets do healthcheck - get: - description: abcd - operationId: FetchHealth - tags: - - Api20100401HealthCheck - responses: - '200': - content: - application/json: - schema: - type: object - title: ListHealthCheck - x-class-extra-annotation: '@JacksonXmlRootElement(localName = \"Healthcheck\")' - properties: - status: - items: - type: string - type: array - description: OK - x-twilio: - pathType: list - x-ignore: true - transactions: - - name: validateHealthCheck - request: - formParams: { } - method: GET - queryParams: { } - url: https://api.twilio.com/healthcheck.json - response: - content: - status: OK - statusCode: 200 diff --git a/src/main/java/com/twilio/oai/TwilioCustomJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioCustomJavaGenerator.java new file mode 100644 index 000000000..9e812db68 --- /dev/null +++ b/src/main/java/com/twilio/oai/TwilioCustomJavaGenerator.java @@ -0,0 +1,136 @@ +package com.twilio.oai; + +import com.samskivert.mustache.Mustache; +import com.twilio.oai.api.JavaApiResources; +import com.twilio.oai.tmp.JavaApiResource; +import com.twilio.oai.tmp.JavaApiResourceBuilder; +import com.twilio.oai.common.ApplicationConstants; +import com.twilio.oai.common.EnumConstants; +import com.twilio.oai.common.Utility; +import com.twilio.oai.templating.mustache.ReplaceHyphenLambda; +import com.twilio.oai.resolver.LanguageConventionResolver; +import com.twilio.oai.resolver.common.CodegenModelResolver; +import com.twilio.oai.resolver.java.JavaCaseResolver; +import com.twilio.oai.resolver.java.JavaParameterResolver; +import com.twilio.oai.resolver.java.JavaPropertyResolver; +import com.twilio.oai.resolver.IConventionMapper; +import com.twilio.oai.resource.ResourceMap; + +import com.twilio.oai.template.IApiActionTemplate; +import com.twilio.oai.template.JavaApiActionTemplate; +import com.twilio.oai.tmp.JavaOperationProcessor; +import com.twilio.oai.tmp.TemplateModifier; +import io.swagger.v3.oas.models.OpenAPI; +import org.openapitools.codegen.*; +import org.openapitools.codegen.languages.JavaClientCodegen; +import org.openapitools.codegen.model.ModelMap; +import org.openapitools.codegen.model.ModelsMap; +import org.openapitools.codegen.model.OperationsMap; + +import java.util.*; + +import com.google.common.collect.ImmutableMap; +import com.samskivert.mustache.Mustache.Lambda; + +import static com.twilio.oai.common.ApplicationConstants.*; + + +public class TwilioCustomJavaGenerator extends JavaClientCodegen { + + private final TemplateModifier templateModifier; + private final DirectoryStructureService directoryStructureService = new DirectoryStructureService( + additionalProperties, + new ResourceMap(new Inflector()), + new JavaCaseResolver()); + private final IConventionMapper conventionMapper = new LanguageConventionResolver(CONFIG_JAVA_JSON_PATH); + private final List allModels = new ArrayList<>(); + + public TwilioCustomJavaGenerator() { + super(); + templateModifier = new TemplateModifier(this); + sourceFolder = ""; + this.typeMapping.put("string+abc", "CustomType"); + this.importMapping.put("CustomType", "hello.import.CustomType"); + System.out.println(this.typeMapping()); + } + + @Override + public void processOpts() { + super.processOpts(); + sourceFolder = ""; + templateModifier.resetPredefinedTemplate(); + this.filesMetadataFilename = ""; + this.versionMetadataFilename = ""; + // Mustache file lookup location + setTemplateDir("twilio-java-custom"); + setModelPackage("models"); + apiTemplateFiles().put("api.mustache", ".java"); + + } + + @Override + public void processOpenAPI(final OpenAPI openAPI) { + super.processOpenAPI(openAPI); + this.setApiPackage("hello"); + this.setOutputDir("hello"); + + + this.openAPI = openAPI; + } + +// @Override +// public String toParamName(final String name) { +// return super.toVarName(twilioCodegen.toParamName(name)); +// } + + +// @Override +// public String toApiFilename(final String name) { +// return directoryStructureService.toApiFilename(super.toApiFilename(name)); +// } + +// @Override +// public Map postProcessAllModels(final Map allModels) { +// final Map results = super.postProcessAllModels(allModels); +// +// Utility.addModelsToLocalModelList(results, this.allModels); +// directoryStructureService.postProcessAllModels(results, modelFormatMap); +// +// // Return an empty collection so no model files get generated. +// return new HashMap<>(); +// } + + @Override + public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, List allModels) { + + final OperationsMap results = super.postProcessOperationsWithModels(objs, allModels); + // final List opList = directoryStructureService.processOperations(results); + JavaApiResource apiResource = processCodegenOperations(results.getOperations().getOperation()); + results.put("resources", apiResource); + return results; + } + + @Override + protected ImmutableMap.Builder addMustacheLambdas() { + ImmutableMap.Builder lambdaBuilder = super.addMustacheLambdas(); + lambdaBuilder.put("replacehyphen", new ReplaceHyphenLambda()); + return lambdaBuilder; + } + + @Override + public String getName() { + return EnumConstants.Generator.TWILIO_JAVA_CUSTOM.getValue(); + } + + @Override + public String getHelp() { + return "Generates the twilio-java helper library."; + } + + private JavaApiResource processCodegenOperations(List opList) { + JavaOperationProcessor operationProcessor = new JavaOperationProcessor(); + JavaApiResourceBuilder javaApiResourceBuilder = new JavaApiResourceBuilder(opList, operationProcessor); + javaApiResourceBuilder.process(); + return javaApiResourceBuilder.build(); + } +} diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index dbd6f9981..88a0d2ce1 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -49,6 +49,9 @@ public TwilioJavaGenerator() { super(); twilioCodegen = new TwilioCodegenAdapter(this, getName()); sourceFolder = ""; + this.typeMapping.put("string+abc", "CustomType"); + this.importMapping.put("CustomType", "hello.import.CustomType"); + System.out.println(this.typeMapping()); } @Override @@ -157,7 +160,7 @@ protected ImmutableMap.Builder addMustacheLambdas() { @Override public String getName() { - return EnumConstants.Generator.TWILIO_JAVA.getValue(); + return EnumConstants.Generator.TWILIO_CSHARP.getValue(); } @Override diff --git a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java index a8b586882..8a63c7e47 100644 --- a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java @@ -130,17 +130,17 @@ public ApiResourceBuilder updateOperations(Resolver codegenPar co.vendorExtensions = conventionResolver.populateSecurityAttributes(co); jsonRequestBodyResolver.setResourceName(resourceName); - co.allParams.stream() - .filter(item -> (item.getContent() != null && item.getContent().get("application/json") != null)) - .forEach(item -> { - CodegenModel model = getModel(item.dataType); - // currently supporting required and conditional parameters only for request body object - if (model != null) { - model.vendorExtensions.put("x-constructor-required", true); - model.vendorExtensions.put("x-model-parameters", generateSignatureListBody(co)); - jsonRequestBodyResolver.resolve(item, codegenParameterIResolver); - } - }); +// co.allParams.stream() +// .filter(item -> (item.getContent() != null && item.getContent().get("application/json") != null)) +// .forEach(item -> { +// CodegenModel model = getModel(item.dataType); +// // currently supporting required and conditional parameters only for request body object +// if (model != null) { +// model.vendorExtensions.put("x-constructor-required", true); +// model.vendorExtensions.put("x-model-parameters", generateSignatureListBody(co)); +// jsonRequestBodyResolver.resolve(item, codegenParameterIResolver); +// } +// }); co.allParams.forEach(this::updateHeaderParamsList); co.pathParams = co.pathParams.stream() .map(item -> codegenParameterIResolver.resolve(item, this)) diff --git a/src/main/java/com/twilio/oai/common/EnumConstants.java b/src/main/java/com/twilio/oai/common/EnumConstants.java index ece88e42f..dd59ee0e6 100644 --- a/src/main/java/com/twilio/oai/common/EnumConstants.java +++ b/src/main/java/com/twilio/oai/common/EnumConstants.java @@ -10,6 +10,7 @@ public class EnumConstants { public enum Generator { TWILIO_CSHARP("twilio-csharp"), TWILIO_JAVA("twilio-java"), + TWILIO_JAVA_CUSTOM("twilio-java-custom"), TWILIO_NODE("twilio-node"), TWILIO_PHP("twilio-php"), TWILIO_PYTHON("twilio-python"), diff --git a/src/main/java/com/twilio/oai/resolver/java/JavaParameterResolver.java b/src/main/java/com/twilio/oai/resolver/java/JavaParameterResolver.java index a384b2c1b..9906d3b59 100644 --- a/src/main/java/com/twilio/oai/resolver/java/JavaParameterResolver.java +++ b/src/main/java/com/twilio/oai/resolver/java/JavaParameterResolver.java @@ -29,46 +29,46 @@ public JavaParameterResolver(IConventionMapper mapper) { @Override public void resolveProperties(CodegenParameter parameter, ApiResourceBuilder apiResourceBuilder) { - if((parameter.dataType.equalsIgnoreCase(OBJECT) || parameter.dataType.equals(LIST_OBJECT)) && parameter.vendorExtensions.get("x-is-anytype") == null) { - String objectType = mapper.properties().getString(OBJECT).orElseThrow(); - - if (parameter.isAnyType || (parameter.isArray && parameter.items.isAnyType)) { - objectType = "Object"; - parameter.vendorExtensions.put("x-is-anytype", true); - } - - else - parameter.isFreeFormObject = true; - - if (parameter.dataType.equals(LIST_OBJECT)) { - parameter.dataType = ApplicationConstants.LIST_START + objectType + ApplicationConstants.LIST_END; - parameter.baseType = objectType; - } else { - parameter.dataType = objectType; - } - } - - mapper.promotions().getMap(parameter.dataFormat).ifPresent(promotions -> { - // cloning to prevent update in source map - HashMap promotionsMap = new HashMap<>(promotions); - promotionsMap.replaceAll((dataType, value) -> value.replaceAll("\\{.*}", parameter.paramName) ); - parameter.vendorExtensions.put(ApplicationConstants.PROMOTION_EXTENSION_NAME, promotionsMap); - }); - - codegenParameterResolver.resolve(parameter, apiResourceBuilder); - - if( PHONE_NUMBER_FORMAT.equals(parameter.dataFormat)) { - parameter.vendorExtensions.put(X_IS_PHONE_NUMBER_FORMAT, true); - } - // prevent special format properties to be considered as enum - mapper.properties().get(parameter.dataFormat).ifPresent(prop -> { - parameter.isEnum = false; - parameter.allowableValues = null; - }); - parameter.paramName = StringHelper.toFirstLetterLower(parameter.paramName); - if (apiResourceBuilder.getToggleMap().getOrDefault(EnumConstants.Generator.TWILIO_JAVA.getValue(), Boolean.FALSE) ) { - resolveIngressModel(parameter, apiResourceBuilder); - } +// if((parameter.dataType.equalsIgnoreCase(OBJECT) || parameter.dataType.equals(LIST_OBJECT)) && parameter.vendorExtensions.get("x-is-anytype") == null) { +// String objectType = mapper.properties().getString(OBJECT).orElseThrow(); +// +// if (parameter.isAnyType || (parameter.isArray && parameter.items.isAnyType)) { +// objectType = "Object"; +// parameter.vendorExtensions.put("x-is-anytype", true); +// } +// +// else +// parameter.isFreeFormObject = true; +// +// if (parameter.dataType.equals(LIST_OBJECT)) { +// parameter.dataType = ApplicationConstants.LIST_START + objectType + ApplicationConstants.LIST_END; +// parameter.baseType = objectType; +// } else { +// parameter.dataType = objectType; +// } +// } +// +// mapper.promotions().getMap(parameter.dataFormat).ifPresent(promotions -> { +// // cloning to prevent update in source map +// HashMap promotionsMap = new HashMap<>(promotions); +// promotionsMap.replaceAll((dataType, value) -> value.replaceAll("\\{.*}", parameter.paramName) ); +// parameter.vendorExtensions.put(ApplicationConstants.PROMOTION_EXTENSION_NAME, promotionsMap); +// }); +// +// codegenParameterResolver.resolve(parameter, apiResourceBuilder); +// +// if( PHONE_NUMBER_FORMAT.equals(parameter.dataFormat)) { +// parameter.vendorExtensions.put(X_IS_PHONE_NUMBER_FORMAT, true); +// } +// // prevent special format properties to be considered as enum +// mapper.properties().get(parameter.dataFormat).ifPresent(prop -> { +// parameter.isEnum = false; +// parameter.allowableValues = null; +// }); +// parameter.paramName = StringHelper.toFirstLetterLower(parameter.paramName); +// if (apiResourceBuilder.getToggleMap().getOrDefault(EnumConstants.Generator.TWILIO_JAVA.getValue(), Boolean.FALSE) ) { +// resolveIngressModel(parameter, apiResourceBuilder); +// } } private void resolveIngressModel(CodegenParameter parameter, ApiResourceBuilder apiResourceBuilder) { diff --git a/src/main/java/com/twilio/oai/resolver/java/JavaPropertyResolver.java b/src/main/java/com/twilio/oai/resolver/java/JavaPropertyResolver.java index 09fe2a11c..7f4460609 100644 --- a/src/main/java/com/twilio/oai/resolver/java/JavaPropertyResolver.java +++ b/src/main/java/com/twilio/oai/resolver/java/JavaPropertyResolver.java @@ -27,27 +27,27 @@ public JavaPropertyResolver(IConventionMapper mapper) { @Override public void resolveProperties(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { super.resolveProperties(property, apiResourceBuilder); - Map> vendorExtensions = new HashMap<>(); - - for (Segments segment : Segments.values()) { - getMapperByType(segment).get(property.dataFormat).ifPresent(value -> { - Map segmentElements = new HashMap<>(); - segmentElements.put(VENDOR_PREFIX + property.dataFormat, - value.toString().replaceAll("\\{.*}", property.name)); - vendorExtensions.put(segment.getSegment(), segmentElements); - }); - } - - property.nameInSnakeCase = StringHelper.toSnakeCase(property.name); - - // Merges the vendorExtensions map with the existing property's vendor extensions - vendorExtensions.forEach( - (key, value) -> property.getVendorExtensions().merge(key, value, (oldValue, newValue) -> newValue) - ); - - if (apiResourceBuilder.getToggleMap().getOrDefault(EnumConstants.Generator.TWILIO_JAVA.getValue(), Boolean.FALSE) ) { - resolveIngressModel(property, apiResourceBuilder); - } +// Map> vendorExtensions = new HashMap<>(); +// +// for (Segments segment : Segments.values()) { +// getMapperByType(segment).get(property.dataFormat).ifPresent(value -> { +// Map segmentElements = new HashMap<>(); +// segmentElements.put(VENDOR_PREFIX + property.dataFormat, +// value.toString().replaceAll("\\{.*}", property.name)); +// vendorExtensions.put(segment.getSegment(), segmentElements); +// }); +// } +// +// property.nameInSnakeCase = StringHelper.toSnakeCase(property.name); +// +// // Merges the vendorExtensions map with the existing property's vendor extensions +// vendorExtensions.forEach( +// (key, value) -> property.getVendorExtensions().merge(key, value, (oldValue, newValue) -> newValue) +// ); +// +// if (apiResourceBuilder.getToggleMap().getOrDefault(EnumConstants.Generator.TWILIO_JAVA.getValue(), Boolean.FALSE) ) { +// resolveIngressModel(property, apiResourceBuilder); +// } } @Override diff --git a/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index e022a1df2..672bad4e6 100644 --- a/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -1,6 +1,7 @@ com.twilio.oai.TwilioCsharpGenerator com.twilio.oai.TwilioGoGenerator com.twilio.oai.TwilioJavaGenerator +com.twilio.oai.TwilioCustomJavaGenerator com.twilio.oai.TwilioNodeGenerator com.twilio.oai.TwilioPhpGenerator com.twilio.oai.TwilioPythonGenerator diff --git a/src/main/resources/twilio-java-custom/api.mustache b/src/main/resources/twilio-java-custom/api.mustache new file mode 100644 index 000000000..a9db4319e --- /dev/null +++ b/src/main/resources/twilio-java-custom/api.mustache @@ -0,0 +1 @@ +# this is dummy test code. \ No newline at end of file diff --git a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java index b77ba704e..be3855324 100644 --- a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java +++ b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java @@ -1,11 +1,13 @@ package com.twilio.oai; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import org.apache.commons.io.FileUtils; import org.junit.BeforeClass; @@ -28,7 +30,7 @@ public class TwilioGeneratorTest { @Parameterized.Parameters public static Collection generators() { - return Arrays.asList(Generator.TWILIO_JAVA); + return Arrays.asList(Generator.TWILIO_JAVA_CUSTOM); } private final Generator generator; @@ -39,7 +41,7 @@ public static void setUp() { } @Test - public void launchGenerator() { + public void launchGenerator() throws IOException { final String pathname = "examples/spec/twilio_api_v2010.yaml"; File filesList[] ; File directoryPath = new File(pathname); @@ -48,11 +50,15 @@ public void launchGenerator() { } else { filesList = new File[]{directoryPath}; } + final String configPath = "config.json"; + Map configProperties = new ObjectMapper().readValue(new File(configPath), Map.class); + for (File file: filesList) { final CodegenConfigurator configurator = new CodegenConfigurator() .setGeneratorName(generator.getValue()) .setInputSpec(file.getPath()) .setOutputDir("codegen/" + generator.getValue()) + .setAdditionalProperties(configProperties) .setInlineSchemaNameDefaults(Map.of("arrayItemSuffix", "")) .addGlobalProperty("apiTests", "false") .addGlobalProperty("apiDocs", "false");