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

/aci with invalid parameters returns JSON with undocumented fields #78

Open
davidyuk opened this issue Oct 28, 2021 · 3 comments
Open

Comments

@davidyuk
Copy link
Member

$ curl https://compiler.aepps.com/aci
{"info":"","parameter":"","reason":"validation_error"}
$ curl -d "p=1" -H "Content-Type: application/json" -X POST https://compiler.aepps.com/aci
{"info":{"data":"p=1","error":"invalid_body"},"parameter":"","reason":"validation_error"}

So, in one case info is a string in one case and an object in another.

The swagger file says that aci should return #/definitions/CompilerErrors in case of error, but CompilerErrors should be an array 🤔 The most similar thing to the response is #/definitions/Error, but it doesn't define info and parameter fields.

@hanssv
Copy link
Member

hanssv commented Nov 11, 2021

Swagger isn't good enough to describe the Error unfortunately - it would be something like this I guess:

  Error:
    type: object
    properties:
      reason:
        type: string
      parameter:
        type: string
      info:
        $ref: '#/definitions/ErrorInfo'
    required:
      - reason
      - parameter
  ErrorInfo:
    oneOf:
      type: string
      type: object
      properties:
        data:
          type: string
        error:
          type: string
        path:
          type: any
      required:
        - error

I'll consider just turning the whole error into a string - though it feels kind of backwards making your error less informative just because the language specifying the response is utterly broken 🤷‍♂️

@davidyuk
Copy link
Member Author

though it feels kind of backwards making your error less informative

I also don't like this solution

oneOf works at least in openapi 3.0, the example below I've tested in https://editor.swagger.io/

oneOf example
openapi: 3.0.0
info:
  version: 1.0.0
  title: Sample API
  description: A sample API to illustrate OpenAPI concepts
paths:
  /list:
    get:
      description: Returns a list of stuff              
      responses:
        '200':
          description: Successful response
components:
  schemas:
    Error:
      type: object
      properties:
        reason:
          type: string
        parameter:
          type: string
        info:
          $ref: '#/components/schemas/ErrorInfo'
      required:
        - reason
        - parameter
    ErrorInfo:
      oneOf:
      - type: string
      - type: object
        properties:
          data:
            type: string
          error:
            type: string
          path:
            type: string
        required:
          - error

But still mixing string and object ininfo field looks confusing. Perhaps it can be split into two optional fields.

path:
type: any

any doesn't look clear to me

I need some comments to understand the purpose of these fields:

  • reason -- looks clear, as the general message
  • parameter -- parameter of what?
  • info -- all of this is information, does it mean an additional one? can't it be inlined?
  • error -- one more error message?
  • path -- is it intended to be a filename, numbers of column and row inside it?
  • data ??

@hanssv
Copy link
Member

hanssv commented Nov 15, 2021

We are stuck with OpenApi 2.0 I think, but I don't know too much about swagger/openapi and Erlang. The errors are basically the result of JSON-parsing so data is the input error is the general type of error reason a more detailed error description, path is something JSON:ish I think... This is all happening "before" the compiler so I'm not too familiar with it.

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

2 participants