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
|
outputDir: samples/client/petstore/scala-sttp
|
||||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/scala/petstore.yaml
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/scala/petstore.yaml
|
||||||
templateDir: modules/openapi-generator/src/main/resources/scala-sttp
|
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:
|
additionalProperties:
|
||||||
artifactId: scala-sttp-petstore
|
artifactId: scala-sttp-petstore
|
||||||
|
@ -1617,6 +1617,11 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
* @return the sanitized variable name
|
* @return the sanitized variable name
|
||||||
*/
|
*/
|
||||||
public String toVarName(final String 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)) {
|
if (reservedWords.contains(name)) {
|
||||||
return escapeReservedWord(name);
|
return escapeReservedWord(name);
|
||||||
} else if (name.chars().anyMatch(character -> specialCharReplacements.containsKey(String.valueOf((char) character)))) {
|
} else if (name.chars().anyMatch(character -> specialCharReplacements.containsKey(String.valueOf((char) character)))) {
|
||||||
@ -1634,6 +1639,11 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toParamName(String name) {
|
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'.
|
name = removeNonNameElementToCamelCase(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||||
if (reservedWords.contains(name)) {
|
if (reservedWords.contains(name)) {
|
||||||
return escapeReservedWord(name);
|
return escapeReservedWord(name);
|
||||||
|
@ -276,6 +276,11 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toVarName(String name) {
|
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);
|
String varName = sanitizeName(name);
|
||||||
|
|
||||||
if ("_".equals(varName)) {
|
if ("_".equals(varName)) {
|
||||||
|
@ -262,6 +262,11 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toParamName(String name) {
|
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);
|
return formatIdentifier(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +133,11 @@ public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements Cod
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toParamName(String name) {
|
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
|
// should be the same as variable name
|
||||||
return toVarName(name);
|
return toVarName(name);
|
||||||
}
|
}
|
||||||
|
@ -380,6 +380,11 @@ public class ScalaSttp4ClientCodegen extends AbstractScalaCodegen implements Cod
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toParamName(String name) {
|
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);
|
return formatIdentifier(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,6 +398,11 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toParamName(String name) {
|
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);
|
return formatIdentifier(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,6 +139,11 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toParamName(String name) {
|
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
|
// should be the same as variable name
|
||||||
return toVarName(name);
|
return toVarName(name);
|
||||||
}
|
}
|
||||||
|
@ -566,6 +566,41 @@ paths:
|
|||||||
description: User not found
|
description: User not found
|
||||||
security:
|
security:
|
||||||
- api_key: []
|
- 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:
|
externalDocs:
|
||||||
description: Find out more about Swagger
|
description: Find out more about Swagger
|
||||||
url: 'http://swagger.io'
|
url: 'http://swagger.io'
|
||||||
@ -758,3 +793,13 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
type: object
|
type: object
|
||||||
|
PropertyNameMapping:
|
||||||
|
properties:
|
||||||
|
http_debug_operation:
|
||||||
|
type: string
|
||||||
|
_type:
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
type_:
|
||||||
|
type: string
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
README.md
|
README.md
|
||||||
build.sbt
|
build.sbt
|
||||||
project/build.properties
|
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/PetApi.scala
|
||||||
src/main/scala/org/openapitools/client/api/StoreApi.scala
|
src/main/scala/org/openapitools/client/api/StoreApi.scala
|
||||||
src/main/scala/org/openapitools/client/api/UserApi.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/EnumTest.scala
|
||||||
src/main/scala/org/openapitools/client/model/Order.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/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/Tag.scala
|
||||||
src/main/scala/org/openapitools/client/model/User.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
|
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* | **addPet** | **POST** /pet | Add a new pet to the store
|
||||||
*PetApi* | **deletePet** | **DELETE** /pet/${petId} | Deletes a pet
|
*PetApi* | **deletePet** | **DELETE** /pet/${petId} | Deletes a pet
|
||||||
*PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status
|
*PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status
|
||||||
@ -94,6 +95,7 @@ Class | Method | HTTP request | Description
|
|||||||
- [EnumTest](EnumTest.md)
|
- [EnumTest](EnumTest.md)
|
||||||
- [Order](Order.md)
|
- [Order](Order.md)
|
||||||
- [Pet](Pet.md)
|
- [Pet](Pet.md)
|
||||||
|
- [PropertyNameMapping](PropertyNameMapping.md)
|
||||||
- [Tag](Tag.md)
|
- [Tag](Tag.md)
|
||||||
- [User](User.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