8000 Support enum models in queryparams · Issue #352 · cjbooms/fabrikt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support enum models in queryparams #352

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

Closed
thejeff77 opened this issue Jan 28, 2025 · 6 comments · Fixed by #354
Closed

Support enum models in queryparams #352

thejeff77 opened this issue Jan 28, 2025 · 6 comments · Fixed by #354

Comments

@thejeff77
Copy link

This works in every openapi generator I've used. When specifying an enum as a queryparam in fabrikt, the generator doesn't fail, but the built code is invalid and doesn't build.

Please support this! Its the biggest issue we run into for extensibility using fabrikt as an alternative for our OAPI models generated code-first in spring boot's springdoc library.

Thanks for any consideration here.

@cjbooms
Copy link
Owner
cjbooms commented Jan 28, 2025

Send in an example spec where this issue occurs please

@thejeff77
Copy link
Author
openapi: 3.0.3
info:
  title: Minimalist API with Enum Parameter
  description: A simple API demonstrating an enum query parameter.
  version: 1.0.0
paths:
  /items:
    get:
      summary: Get items with a status filter
      description: Retrieve a list of items filtered by their status.
      parameters:
        - name: status
          in: query
          required: false
          description: Filter items by status.
          schema:
            type: string
            enum:
              - active
              - inactive
              - archived
      responses:
        "200":
          description: A list of items.
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: integer
                      description: Unique identifier for the item.
                    name:
                      type: string
                      description: Name of the item.
                    status:
                      type: string
                      description: Status of the item.
                      enum:
                        - active
                        - inactive
                        - archived

@cjbooms
Copy link
Owner
cjbooms commented Jan 28, 2025

The problem here is inlined generation from the request parameters section. Fabrikt does not know what classname to give the generated enum.

If you move the definitions to the schemas section and reference it, it will work fine:

openapi: 3.0.3
info: {}
paths:
  /items:
    get:
      summary: Get items with a status filter
      description: Retrieve a list of items filtered by their status.
      parameters:
        - name: status
          in: query
          required: false
          description: Filter items by status.
          schema:
            $ref: '#/components/schemas/Status'
      responses:
        "200":
components:
  schemas:
    Status:
      type: string
      enum:
        - active
        - inactive
        - archived

I found and fixed a different fabrikt bug with array generation from the sample you provided though.

@cjbooms
Copy link
Owner
cjbooms commented Jan 29, 2025

I have added logic to detect unsupported inlined schemas and default them to either String for enums or Any for objects. This should at least help generate working code.
Your spec now produces the following

Image

@thejeff77
Copy link
Author

Thanks for the fix @cjbooms !!

This is great however I failed to specify this is for client generation, not the server.

It generates code that fails to compile.

@cjbooms
Copy link
Owner
cjbooms commented Jan 29, 2025

Thanks for the fix @cjbooms !!

This is great however I failed to specify this is for client generation, not the server.

It generates code that fails to compile.

Should be fixed centrally within fabrikt's type system. Please check here and report back if still an issue:
https://fabrikt.fly.dev/

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

Successfully merging a pull request may close this issue.

2 participants
0