Skip to content

Found Bug in OpenAPI Docs - not correctly reflecting Models 🐛 #367

@wetisobe

Description

@wetisobe

Describe the bug 🐛
The file openapi.json does not reflect endpoints correctly, it does not parse input objects correctly. When accepting a custom model as input to a post request, it is not reflected correctly to the openapi.json and the endpoint /docs/swagger.

To Reproduce 👨‍🔬
This is a minimal example:

import happyx

# Here are the enums
type
    options_encoding* = enum
        encodingA, encodingB

# here is some model 
model DataProcessRequest: 
    data: string = ""
    storage: options_encoding = encodingA
    xtemplate: string = "" 

# Serve at http://127.0.0.1:5000
serve "0.0.0.0", 5000:

  # on GET HTTP method at http://127.0.0.1:5000/
  get "/":
    {.gcsafe.}:
      return %*{
        "response": "success",
        "msg": "These are not the droids, you're looking for."
      }

  post "/api/process[r:DataProcessRequest:json]":
    {.gcsafe.}:
      # Return plain text

      # process data here

      return %*{
        "response": "success"
      }
      

The OpenAPI results in this:

{"openapi":"3.1.0","swagger":"2.0","info":{"title":"HappyX OpenAPI Docs","version":"1.0.0"},"paths":{"/":{"get":{"description":"","parameters":[],"requestBody":{},"responses":{}}},"/api/process":{"post":{"description":"","parameters":[],"requestBody":{},"responses":{}}}},"components":{"schemas":{"DataProcessRequest":{"type":"object","properties":{"data":{"type":"string"},"xtemplate":{"type":"string"}}}},"parameters":{},"responses":{},"securitySchemas":{},"headers":{},"links":{},"callbacks":{},"pathItems":{},"examples":{},"requestBodies":{},"/":{},"/api/process":{}}}

As you can see the Object is missing the enum, also it is not reflected to the frontend (see screenshot).
(Also the correct return codes are missing as this can only return a 200, but this is a minor thing in this case)

Expected behavior 🤔
I expect the two endpoints to be visible and correctly typed in the openapi.json.

Screenshots 🖼
grafik

Please complete the following information 📃

  • OS: Ubuntu
  • OS Version 22.04
  • HappyX version 4.6.2
  • HappyX project type [ssr/spa]
  • HappyX project language Nim
  • Nim version 2.0.4
  • HTTP Server Default

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions