swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.91k stars 6.03k forks source link

why x-spring-paginated vender extentions doesn't work for me? #5506

Open zzsoszz opened 7 years ago

zzsoszz commented 7 years ago
Description

is there any way to make it works? https://github.com/swagger-api/swagger-codegen/issues/3353 https://github.com/swagger-api/swagger-codegen/pull/3357

json code

  "/pet/findByStatus": {
      "get": {
        "tags": [
          "pet"
        ],
        "summary": "Finds Pets by status",
        "description": "Multiple status values can be provided with comma seperated strings",
        "operationId": "findPetsByStatus",
        "x-spring-paginated": true,
        "produces": [
          "application/json",
          "application/xml"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "description": "Status values that need to be considered for filter",
            "required": false,
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["available", "pending", "sold"]
            },
            "collectionFormat": "multi",
            "default": "available"
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/Pet"
              }
            },
            "examples": {
              "application/json": {
                "name": "Puma",
                "type": "Dog",
                "color": "Black",
                "gender": "Female",
                "breed": "Mixed"
              }
            }
          },
          "400": {
            "description": "Invalid status value"
          }
        },
        "security": [
          {
            "petstore_auth": [
              "write:pets",
              "read:pets"
            ]
          }
        ]
      }
    }

generated java source

    public ResponseEntity<List<Pet>> findPetsByStatus( @ApiParam(value = "Status values that need to be considered for filter", allowableValues = "AVAILABLE, PENDING, SOLD", defaultValue = "available") @RequestParam(value = "status", required = false, defaultValue="available") List<String> status) {
        // do some magic!
        return new ResponseEntity<List<Pet>>(HttpStatus.OK);
    }
wing328 commented 7 years ago

@zzsoszz looks like it's removed somehow 😞

@cbornet @diyfr would you please take a look when you've time?

mkatircioglu commented 6 years ago

Is there any update on this? @wing328

cbornet commented 6 years ago

It seems @diyfr ‘s PR was never merged

mkatircioglu commented 6 years ago

What should we do now? @cbornet Can we merge @diyfr 's PR on the behalf of him?

mikhail-putilov commented 5 years ago

Hey guys, is there any update? This issue is a big deal for me since my team and I use spring-mvc rather extensively and this is the only issue that stops me from trying codegen in production.

T9FC8FY commented 5 years ago

Hi, is there a update? In our project we want to generate our APIs, but the Pageable and Page objects are the reason why we still dont do this.

diyfr commented 5 years ago

This feature has not been finalized because it's very specific to SpringFramework. It's been a while since I use Spring anymore, I often use SparkJava it's most light for micro services. If you think it's necessary, I'll see if I can find some time to implement it.(You can also contribute :) PR3357 ) If not, in my projects I treat it this way Add query parameters for each resources :

      parameters:
        - $ref: '#/parameters/ppage'
        - $ref: '#/parameters/psize'
        - $ref: '#/parameters/psort'

Don't miss to add a partial response

        '206':
          description: 'Partial Content'
          schema:
            type: 'array'
            items:
              $ref: '#/definitions/Pet

or (see best practise)

        '206':
          description: 'Partial Content'
          schema:
            $ref: '#/definitions/Pets'

Define parameters for all project

parameters:
  ppage:
    name: 'page'
    in: 'query'
    description: 'Results page you want to retrieve (0..N)'
    type: 'integer'
  psize:
    name: 'size'
    in: 'query'
    description: 'Number of records per page.'
    type: 'integer'
  psort:
    name: 'sort'
    in: 'query'
    description: 'Sorting criteria property(,asc|desc) Default sort order is ascending. Multiple sort criteria are supported.'
    uniqueItems: true
    collectionFormat: 'pipes'
    type: 'array'
    items:
      type: 'string'

Best practise encapsulate your paginated response :

  Pets:
    type: 'object'
    properties:
      page:
        type: 'integer'
        format: 'int32'
      size:
        type: 'integer'
        format: 'int32'
      sort:
        type: 'string'
      total:
        type: 'integer'
        format: 'int64'
      count:
        type: 'integer'
        format: 'int32'
      results:
        type: 'array'
        items:
          $ref: '#/definitions/Pet'

You can also added in your response HTTP header X-Pagination-Count, X-Pagination-Page, X-Pagination-Limit it's more standard, and applicable for all generators

@wing328 The pull request must be submitted to SwaggerCodeGen or OpenApiGenerator ?

wutzebaer commented 4 years ago

This feature has not been finalized because it's very specific to SpringFramework. It's been a while since I use Spring anymore, I often use SparkJava it's most light for micro services. If you think it's necessary, I'll see if I can find some time to implement it.(You can also contribute :) PR3357 ) If not, in my projects I treat it this way Add query parameters for each resources :

      parameters:
        - $ref: '#/parameters/ppage'
        - $ref: '#/parameters/psize'
        - $ref: '#/parameters/psort'

Don't miss to add a partial response

        '206':
          description: 'Partial Content'
          schema:
            type: 'array'
            items:
              $ref: '#/definitions/Pet

or (see best practise)

        '206':
          description: 'Partial Content'
          schema:
            $ref: '#/definitions/Pets'

Define parameters for all project

parameters:
  ppage:
    name: 'page'
    in: 'query'
    description: 'Results page you want to retrieve (0..N)'
    type: 'integer'
  psize:
    name: 'size'
    in: 'query'
    description: 'Number of records per page.'
    type: 'integer'
  psort:
    name: 'sort'
    in: 'query'
    description: 'Sorting criteria property(,asc|desc) Default sort order is ascending. Multiple sort criteria are supported.'
    uniqueItems: true
    collectionFormat: 'pipes'
    type: 'array'
    items:
      type: 'string'

Best practise encapsulate your paginated response :

  Pets:
    type: 'object'
    properties:
      page:
        type: 'integer'
        format: 'int32'
      size:
        type: 'integer'
        format: 'int32'
      sort:
        type: 'string'
      total:
        type: 'integer'
        format: 'int64'
      count:
        type: 'integer'
        format: 'int32'
      results:
        type: 'array'
        items:
          $ref: '#/definitions/Pet'

You can also added in your response HTTP header X-Pagination-Count, X-Pagination-Page, X-Pagination-Limit it's more standard, and applicable for all generators

@wing328 The pull request must be submitted to SwaggerCodeGen or OpenApiGenerator ?

and how do you parse the parameters into a Pageable? it seems complicated to parse the sort parameter, when i have a look at SortHandlerMethodArgumentResolver