Closed y9san9 closed 4 years ago
Is there possibility to rename parameters as in Gson library ?
I want generate parameters with different name in Kotlin and Json
I'll see if you can add it as a module or not, if not i'll try to add functionality to allow the handling of such cases.
Ok, waiting for reply
you can use replaceModule in the config, and replace this default module https://github.com/papsign/Ktor-OpenAPI-Generator/blob/master/src/main/kotlin/com/papsign/ktor/openapigen/schema/builder/provider/DefaultObjectSchemaProvider.kt with one that takes in account the name from the annotation, this is the relevant part:
SchemaModel.SchemaModelObj<Any?>(
props.associate {
// change name here if it is annotated
Pair(it.name, builder.build(it.type, it.source.annotations))
},
props.filter {
!it.type.isMarkedNullable
}.map { it.name } // make sure to have the right name here as well
)
in the config:
replaceModule(DefaultObjectSchemaProvider, CustomObjectSchemaProvider)
Allowing a more generic modification requires quite a bit more work, probably a system like the validators but the module detects the annotation instead of the other way around.
If you want such an extension system feel free to open another issue.
should I extend my class from it? It is final type as I see
no, you create a new one, and replace the default module with yours using replaceModule in the config.
make sure you implement SchemaBuilderProviderModule
, it is the required interface for it to work
Can I do same with parameters ? I wanna name header 'token' in Kotlin and 'Authorization' in request (without Auth)
Yes normally you should be able to, look which module instanciates the header's model. All openapi structures are defined in the models package, it should be 1:1 to the spec, look what module instanciates the model you wish to customize, and replace the module with a custom one.
Ok thanks