OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.3k stars 6.44k forks source link

String type defined with "pattern" is generated as Object instead of String #972

Open srividhyak27 opened 6 years ago

srividhyak27 commented 6 years ago
Description

We have a type defined as string along-with pattern

sid:
      type: string
      pattern: '^(phone-[0-9]{5,15}|extphone-.+|.+)$'

This is referenced as a parameter in POST method:

 parameters:
        - name: sid
          in: path
          description: SID of the user
          required: true
          schema:
             $ref: './common.yaml#/components/schemas/sid

The service stub generated has parameter "sid" defined as object, as shown below: addUser(@ApiParam(value = "SID of user",required=true) @PathParam("sid") Object sid,....)

This throws Jersey Model validation errors while running the service.

I changed the type of the parameter to "string" and the service works fine. Is there any way code/class for such parameter (with patterns/regular expressions) can be generated and referenced ?

openapi-generator version

openapi-generator maven plugin, version 3.1.2

OpenAPI declaration file content or url
Command line used for generation
jaxrs-jersey
Steps to reproduce

specification example provided above

Related issues/PRs
Suggest a fix/enhancement

For parameters in URI path, can we fallback to String (instead of Object) in case the relevant type cannot be generated ?

wing328 commented 6 years ago

openapi-generator maven plugin, version 3.1.2

Can you try the latest stable version, which has better support for reference to primitive type?