Git Product home page Git Product logo

Comments (8)

eneko avatar eneko commented on May 28, 2024

I can reproduce this issue at http://editor.swagger.io, by pasting the JSON listed above.

There seem to be two issues:

1. Parameters are missing the schema.

Not sure why this is required, it might be a bug, since both the editor and Swagger UI complain about schema missing.

By adding the schema to parameters, we solve this issue:

 parameters:
        - deprecated: false
          allowEmptyValue: false
          in: query
          name: offset
          description: offset description
          required: false
          schema:
            type: integer
            format: int64
        - deprecated: false
          allowEmptyValue: false
          in: query
          name: limit
          description: limit description
          required: false
          schema:
            type: integer
            format: int64

2. Incorrect type specified for integer fields

In the JSON above, MyObject has an id field of type int. The correct type is integer, adding format int64 as follows:

MyObject:
      type: object
      properties:
        name:
          type: string
          example: name of the object
        id:
          type: integer
          format: int64
          example: '100'

from swiftgger.

eneko avatar eneko commented on May 28, 2024

Hi @TofPlay.

Would you mind updating to version 1.3.0 to see if the PR above addresses your issue?

from swiftgger.

TofPlay avatar TofPlay commented on May 28, 2024

@eneko with version 1.3.0 I have the error

Errors
Hide
 
Fetch errorFailed to fetch http://locahost:8080/swagger.json
Fetch errorPossible cross-origin (CORS) issue? The URL origin (http://locahost:8080) does not match the page (http://localhost:8888). Check the server returns the correct 'Access-Control-Allow-*' headers.

When I check my server API I have:

$ curl -I http://localhost:8080/swagger.json
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,HEAD,OPTIONS
Access-Control-Request-Headers: Content-Type, api_key, Authorization
content-type: application/json; charset=utf-8
content-length: 5791
date: Sun, 03 Feb 2019 21:08:16 GMT
Connection: keep-alive

It should be valid but has there something that does not like Swagger UI

from swiftgger.

eneko avatar eneko commented on May 28, 2024

To verify the spec generation is working, you can get the JSON output from http://localhost:8080/swagger.json and paste it on http://editor.swagger.io (tap Ok to convert to YAML). Does is show you any validation errors?

If the spec is correct, then you might have an issue somewhere else. It seems, from your comment, you might have a mix of ports (8080 vs 8888).

from swiftgger.

TofPlay avatar TofPlay commented on May 28, 2024

To verify the spec generation is working, you can get the JSON output from http://localhost:8080/swagger.json

I tested with http://editor.swagger.io and the json is valid

you might have a mix of ports (8080 vs 8888)

Sure the server is running on port 8080 and Swagger UI is running has a docker image on port 8888
They are each in their environment but Swagger UI should be able to access the API server. During my first test I had no problem with CORS

from swiftgger.

eneko avatar eneko commented on May 28, 2024

Glad to hear the JSON output is valid 🎉

In regards of Swagger UI, this is probably outside of the realm of this library.

My understanding is both Swagger UI and the spec JSON file should live on the same hostname, to avoid any CORS issues. A couple of ideas to try:

  1. Serve Swagger UI from your server, as static files under a specific url path.
  2. Open your swagger UI index.html directly in the browser, or use python -m SimpleHTTPServer instead of Docker. If it's just for testing locally, it's faster and easier to setup.

Good luck!

from swiftgger.

TofPlay avatar TofPlay commented on May 28, 2024

In regards of Swagger UI, this is probably outside of the realm of this library.

@eneko You're right, thank you for your help 🙂

from swiftgger.

eneko avatar eneko commented on May 28, 2024

Happy to help and thank you for using Swiftgger! Let us know if you find any other issues with the JSON spec.

from swiftgger.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.