oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

feat: add support for schema keywords

Open cowboy-bebug opened this issue 1 month ago • 0 comments

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 avatar Nov 19 '25 07:11 cowboy-bebug