forked from loafle/openapi-generator-original
add name, parameter mapping to scala generators (#16194)
This commit is contained in:
parent
954d41b9aa
commit
5d2e80977b
@ -2,5 +2,13 @@ generatorName: scala-sttp
|
||||
outputDir: samples/client/petstore/scala-sttp
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/scala/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/scala-sttp
|
||||
nameMappings:
|
||||
_type: "`underscoreType`"
|
||||
type_: "`typeWithUnderscore`"
|
||||
http_debug_operation: "`httpDebugOperation`"
|
||||
parameterNameMappings:
|
||||
_type: underscoreType
|
||||
type_: typeWithUnderscore
|
||||
http_debug_operation: httpDebugOperation
|
||||
additionalProperties:
|
||||
artifactId: scala-sttp-petstore
|
||||
|
@ -1617,6 +1617,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @return the sanitized variable name
|
||||
*/
|
||||
public String toVarName(final String name) {
|
||||
// obtain the name from nameMapping directly if provided
|
||||
if (nameMapping.containsKey(name)) {
|
||||
return nameMapping.get(name);
|
||||
}
|
||||
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
} else if (name.chars().anyMatch(character -> specialCharReplacements.containsKey(String.valueOf((char) character)))) {
|
||||
@ -1634,6 +1639,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// obtain the name from parameterNameMapping directly if provided
|
||||
if (parameterNameMapping.containsKey(name)) {
|
||||
return parameterNameMapping.get(name);
|
||||
}
|
||||
|
||||
name = removeNonNameElementToCamelCase(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
|
@ -276,6 +276,11 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// obtain the name from nameMapping directly if provided
|
||||
if (nameMapping.containsKey(name)) {
|
||||
return nameMapping.get(name);
|
||||
}
|
||||
|
||||
String varName = sanitizeName(name);
|
||||
|
||||
if ("_".equals(varName)) {
|
||||
|
@ -159,15 +159,15 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
||||
if (additionalProperties.containsKey("mainPackage")) {
|
||||
setMainPackage((String) additionalProperties.get("mainPackage"));
|
||||
additionalProperties.replace("configKeyPath", this.configKeyPath);
|
||||
if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)){
|
||||
if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
|
||||
apiPackage = mainPackage + ".api";
|
||||
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
}
|
||||
if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)){
|
||||
if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
|
||||
modelPackage = mainPackage + ".model";
|
||||
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
}
|
||||
if (!additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)){
|
||||
if (!additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
invokerPackage = mainPackage + ".core";
|
||||
}
|
||||
}
|
||||
@ -262,6 +262,11 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// obtain the name from parameterNameMapping directly if provided
|
||||
if (parameterNameMapping.containsKey(name)) {
|
||||
return parameterNameMapping.get(name);
|
||||
}
|
||||
|
||||
return formatIdentifier(name, false);
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,11 @@ public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements Cod
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// obtain the name from parameterNameMapping directly if provided
|
||||
if (parameterNameMapping.containsKey(name)) {
|
||||
return parameterNameMapping.get(name);
|
||||
}
|
||||
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
@ -380,6 +380,11 @@ public class ScalaSttp4ClientCodegen extends AbstractScalaCodegen implements Cod
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// obtain the name from parameterNameMapping directly if provided
|
||||
if (parameterNameMapping.containsKey(name)) {
|
||||
return parameterNameMapping.get(name);
|
||||
}
|
||||
|
||||
return formatIdentifier(name, false);
|
||||
}
|
||||
|
||||
|
@ -398,6 +398,11 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// obtain the name from parameterNameMapping directly if provided
|
||||
if (parameterNameMapping.containsKey(name)) {
|
||||
return parameterNameMapping.get(name);
|
||||
}
|
||||
|
||||
return formatIdentifier(name, false);
|
||||
}
|
||||
|
||||
|
@ -139,6 +139,11 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// obtain the name from parameterNameMapping directly if provided
|
||||
if (parameterNameMapping.containsKey(name)) {
|
||||
return parameterNameMapping.get(name);
|
||||
}
|
||||
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
@ -566,6 +566,41 @@ paths:
|
||||
description: User not found
|
||||
security:
|
||||
- api_key: []
|
||||
/fake/parameter-name-mapping:
|
||||
get:
|
||||
tags:
|
||||
- fake
|
||||
summary: parameter name mapping test
|
||||
operationId: getParameterNameMapping
|
||||
parameters:
|
||||
- name: _type
|
||||
in: header
|
||||
description: _type
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
- name: type
|
||||
in: query
|
||||
description: type
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- name: type_
|
||||
in: header
|
||||
description: type_
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- name: http_debug_option
|
||||
in: query
|
||||
description: http debug option (to test parameter naming option)
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
externalDocs:
|
||||
description: Find out more about Swagger
|
||||
url: 'http://swagger.io'
|
||||
@ -758,3 +793,13 @@ components:
|
||||
type: string
|
||||
type: array
|
||||
type: object
|
||||
PropertyNameMapping:
|
||||
properties:
|
||||
http_debug_operation:
|
||||
type: string
|
||||
_type:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
type_:
|
||||
type: string
|
||||
|
@ -1,6 +1,7 @@
|
||||
README.md
|
||||
build.sbt
|
||||
project/build.properties
|
||||
src/main/scala/org/openapitools/client/api/FakeApi.scala
|
||||
src/main/scala/org/openapitools/client/api/PetApi.scala
|
||||
src/main/scala/org/openapitools/client/api/StoreApi.scala
|
||||
src/main/scala/org/openapitools/client/api/UserApi.scala
|
||||
@ -12,5 +13,6 @@ src/main/scala/org/openapitools/client/model/Category.scala
|
||||
src/main/scala/org/openapitools/client/model/EnumTest.scala
|
||||
src/main/scala/org/openapitools/client/model/Order.scala
|
||||
src/main/scala/org/openapitools/client/model/Pet.scala
|
||||
src/main/scala/org/openapitools/client/model/PropertyNameMapping.scala
|
||||
src/main/scala/org/openapitools/client/model/Tag.scala
|
||||
src/main/scala/org/openapitools/client/model/User.scala
|
||||
|
@ -65,6 +65,7 @@ All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Class | Method | HTTP request | Description
|
||||
------------ | ------------- | ------------- | -------------
|
||||
*FakeApi* | **getParameterNameMapping** | **GET** /fake/parameter-name-mapping | parameter name mapping test
|
||||
*PetApi* | **addPet** | **POST** /pet | Add a new pet to the store
|
||||
*PetApi* | **deletePet** | **DELETE** /pet/${petId} | Deletes a pet
|
||||
*PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status
|
||||
@ -94,6 +95,7 @@ Class | Method | HTTP request | Description
|
||||
- [EnumTest](EnumTest.md)
|
||||
- [Order](Order.md)
|
||||
- [Pet](Pet.md)
|
||||
- [PropertyNameMapping](PropertyNameMapping.md)
|
||||
- [Tag](Tag.md)
|
||||
- [User](User.md)
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.api
|
||||
|
||||
import org.openapitools.client.core.JsonSupport._
|
||||
import sttp.client3._
|
||||
import sttp.model.Method
|
||||
|
||||
object FakeApi {
|
||||
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new FakeApi(baseUrl)
|
||||
}
|
||||
|
||||
class FakeApi(baseUrl: String) {
|
||||
|
||||
/**
|
||||
* Expected answers:
|
||||
* code 200 : (OK)
|
||||
*
|
||||
* @param underscoreType _type
|
||||
* @param `type` type
|
||||
* @param typeWithUnderscore type_
|
||||
* @param httpDebugOption http debug option (to test parameter naming option)
|
||||
*/
|
||||
def getParameterNameMapping(underscoreType: Long, `type`: String, typeWithUnderscore: String, httpDebugOption: String
|
||||
): Request[Either[ResponseException[String, Exception], Unit], Any] =
|
||||
basicRequest
|
||||
.method(Method.GET, uri"$baseUrl/fake/parameter-name-mapping?type=${ `type` }&http_debug_option=${ httpDebugOption }")
|
||||
.contentType("application/json")
|
||||
.header("_type", underscoreType.toString)
|
||||
.header("type_", typeWithUnderscore.toString)
|
||||
.response(asJson[Unit])
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.client.model
|
||||
|
||||
|
||||
case class PropertyNameMapping(
|
||||
`httpDebugOperation`: Option[String] = None,
|
||||
`underscoreType`: Option[String] = None,
|
||||
`type`: Option[String] = None,
|
||||
`typeWithUnderscore`: Option[String] = None
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user