Skip to content

feat: add support for schema keywords#2162

Open
cowboy-bebug wants to merge 6 commits intooapi-codegen:mainfrom
cowboy-bebug:main
Open

feat: add support for schema keywords#2162
cowboy-bebug wants to merge 6 commits intooapi-codegen:mainfrom
cowboy-bebug:main

Conversation

@cowboy-bebug
Copy link

@cowboy-bebug cowboy-bebug commented Nov 19, 2025

Hi there 👋

I use the tool extensively at work and thought it'd be really great to generate some consts based on the JSON schema keywords.

This PR adds features to handle the keywords such as minimum, maximum, etc.:

paths:
  /users:
    get:
      operationId: listUsers
      summary: List users with pagination and filtering
      description: Demonstrates inline parameter constraints generating constants
      parameters:
        - in: query
          name: limit
          description: Maximum number of items to return
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20

components:
  schemas:
    Username:
      type: string
      minLength: 3
      maxLength: 20
      default: "guest"

as constants:

// Constraint constants for ListUsersLimit.
const (
	ListUsersLimitMinimum int = 1
	ListUsersLimitMaximum int = 100
	ListUsersLimitDefault int = 20
)

// Constraint constants for Username.
const (
	UsernameDefault   string = "guest"
	UsernameMinLength uint64 = 3
	UsernameMaxLength uint64 = 20
)

I didn't find any relevant / related issues. Let me know if this is something valuable to you guys as well 🙏

@cowboy-bebug
Copy link
Author

Hi @jamietanna, just a quick ping on this PR. I’ve been using this locally for a few weeks and it significantly simplifies marrying request validation with the spec file.

I realized this wasn't in the issues list yet, but it feels like a quality of life improvement that would benefit anyone manually adding min/max constants in application.

I've made sure to include tests and documentation to keep the maintenance burden as low as possible for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant