swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Python client generation fails in 2.2.1

Open andreaformica opened this issue 10 years ago • 3 comments

Description

I have a problem in generating a python client from a JAX-RS application due to the usage of special regular expressions in the @Path definition. My method contains the following annotations: @ApiOperation(value = "List tags.", notes = "List tags.", response=SchemaNodeTagType.class, responseContainer="List") @Path("/{schema}/{db}/{node: (.+)?}/tags") public List<SchemaNodeTagType> comaListTagsInNodesSchema( @ApiParam(value = "schema: schema name", required = true) @PathParam("schema") String schema, @ApiParam(value = "db: db name", required = true) @PathParam("db") String db, @ApiParam(value = "node: node name", required = true ) @PathParam("node") String node) { .... } The reason for the definition of the node parameter as a regexp "(.+)?" is due to the fact that it should support strings containing slashes, e.g. : /THIS/IS/MY/NODE Swagger.json puts the regexp inside the parameter in the field pattern: .....,{"name":"node","in":"path","required":true,"type":"string","pattern":"(.+)?"}

This makes swagger python code generation fail with the following message:

Exception: Pattern must follow the Perl /pattern/modifiers convention. (.+)? is not valid. at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:796) at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:688) at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:376) at io.swagger.codegen.cmd.Generate.run(Generate.java:223) at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36) Caused by: java.lang.IllegalArgumentException: Pattern must follow the Perl /pattern/modifiers convention. (.+)? is not valid. at io.swagger.codegen.languages.PythonClientCodegen.postProcessPattern(PythonClientCodegen.java:202) at io.swagger.codegen.languages.PythonClientCodegen.postProcessParameter(PythonClientCodegen.java:183) at io.swagger.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:2380) at io.swagger.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:1961) at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:744) ... 4 more

Swagger-codegen version

I am using swagger-codegen 2.2.1 installed on a MacOSX via homebrew

Swagger declaration file content or url
Command line used for generation

swagger-codegen generate -c ./config.json -i http://localhost:8080/myapp/swagger.json -l python

Steps to reproduce
Related issues
Suggest a Fix

It seems that the error comes from the class PythonClientCodegen.java which wants a Perl like pattern in that field (so it basically impose the usage of slashes: /(.+)?/
This obviously would not then work for my JAXRS definition. Do you have any ideas if I can do things differently to avoid this problem ?

andreaformica avatar Oct 20 '16 09:10 andreaformica

@andreaformica please give the latest master a try as I believe we've fixed it already.

wing328 avatar Oct 20 '16 09:10 wing328

I did a try with the branch 2.3.0, and it works !!! Sorry for the noise then. Let me also comment that swagger is really wonderful !

andreaformica avatar Oct 20 '16 10:10 andreaformica

Glad to hear that you find it useful 😄

wing328 avatar Oct 20 '16 10:10 wing328