Hi Andrew,

You can use a custom converter, possibly the quickest option would be 
something like:

class MyFactory extends ObjectMapperFactory{
    public ObjectMapper createMapper() {
        ObjectMapper mapper = ObjectMapperFactory.createJson();
        mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
        return mapper;
    }
}
class MyConverter extends ModelResolver {
    public MyConverter() {
        super(new MyFactory().createMapper());
    }
}


which applies the customized mapper to the definitions resolver.

Alternatively you can do it similarly in code implementing ModelConverter 
directly, an example with exactly your case is here: 

1.5.x: 
https://github.com/swagger-api/swagger-core/blob/v1.5.16/modules/swagger-core/src/test/java/io/swagger/model/override/SnakeCaseConverterTest.java#L72
2.0.0-rc2: 
https://github.com/swagger-api/swagger-core/blob/v2.0.0-rc2/modules/swagger-core/src/test/java/io/swagger/converting/override/SnakeCaseConverterTest.java#L69

In both cases you need to add the custom converter during bootstrap, e.g.:

ModelConverters.getInstance().addConverter(new MyConverter());


you can also add your custom converter via service loader to 
META-INF/services/io.swagger.converter.ModelConverter

Also possibly you are referring to an old wiki link; Wiki for current 1.5.x 
version is avaliable 
at 
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X

while the one for oncoming 2.x version, currently in RC is 
here:  
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-2.0.X



Il giorno giovedì 19 ottobre 2017 16:47:41 UTC+2, Andrew Craft ha scritto:
>
>
> I have a Jersey jax-rs application that i have configured to generate a 
> swagger document for as described in 
> https://github.com/swagger-api/swagger-core/wiki/swagger-core-jersey-2.x-project-setup
>
> We are using jackson to convert our entity and configured it to use 
> SNAKE_CASE property naming strategy. When running swagger its is picking 
> the default naming strategy and putting those names into the swagger 
> document using camel case. I have tried 
> configuring io.swagger.util.Json.mapper() 
>
>         
> Json.mapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
>
>
> but that ObjectMapper appears to be used globally as not only does it fix 
> the propertynames for my rest entity, the properties in the swagger 
> document also get converted eg 'operationId' on my operations gets changed 
> to operation_id, which is then breaking the swagger-codegen which is 
> experting normal camel case.
>
> Any way i can custom the names generated for properties on my entities? 
> Obviously don't want to go through adding annotations on all my entities 
> but configure swagger to default to snake case.
>
> thanks
> Andrew
>

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to