Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floats are being converted to String #160

Open
vinaybedre opened this issue Jan 22, 2020 · 4 comments
Open

Floats are being converted to String #160

vinaybedre opened this issue Jan 22, 2020 · 4 comments

Comments

@vinaybedre
Copy link

Floats in swagger spec are being converted to String in graphql.

Steps to reproduce:
npx swagger-to-graphql --swagger-schema=swagger_schema.yaml > ./types.graphql

swagger_schema.yaml

swagger: "2.0"
info:
    version: 1.1.0
    title: Test server
basePath: /api/v1
host: localhost
paths:
    /user/{id}:
        get:
            operationId: getUserId
            tags:
                - users
            produces:
                - application/json
            parameters:
                - name: id
                  in: path
                  description: User Id
                  required: true
                  type: integer
                  format: int64
            responses:
                200:
                    description: A User Response
                    schema:
                        $ref: "#/definitions/UserResponse"
definitions:
    UserResponse:
        type: object
        required:
            - userId
        properties:
            userId:
                type: integer
                format: int64
            userName:
                type: string

Expected output:

type Query {
  getUserId(id: Float!): UserResponse!
}

type UserResponse {
  userId: Float!
  userName: String
}

Actual output:

type Query {
  getUserId(id: String!): UserResponse!
}

type UserResponse {
  userId: String!
  userName: String
}
@codef0rmer
Copy link

codef0rmer commented Dec 8, 2020

Same here with int return type

       "WorkflowCaseId": {
          "format": "int64",
          "type": "integer"
        }

Gets back

type WorkflowCaseIdentifier {
  WorkflowCaseId: String
}

Any remedy?

P.S. It's because of format https://github.com/yarax/swagger-to-graphql/blob/master/src/typeMap.ts#L52

@codef0rmer
Copy link

@0xR
Copy link
Collaborator

0xR commented Dec 8, 2020

The JavaScript number type doesn't have enough accuracy to represent a 64 bit integer. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

It's safer to stick to a int32 on your backend. In Java an int would be 32 bit and a long would be 64 bit.

@codef0rmer
Copy link

Thanks @0xR for the clarification 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants