OpenAPITools / OpenAPITools/openapi-generator
[REQ][Golang]Support value validation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
for a spec with value validation (maxLength, maximum, required...)
openapi: 3.0.3
info:
version: 1.0.0
title: Example
servers:
- url: http://localhost:8080
paths:
/data:
get:
responses:
200:
description: example response
content:
application/json:
schema:
type: object
required: [id]
properties:
id:
type: string
maxLength: 10
generate go client by v5.4.0 generate -i openapi.yml -g go
and write code
package main
import (
"context"
"fmt"
openapi "github.com/GIT_USER_ID/GIT_REPO_ID"
"net/http"
)
func main() {
go http.ListenAndServe("127.0.0.1:8080", http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Add("Content-Type", "application/json; charset=utf8")
writer.Write([]byte("{}"))
}))
data, _, err := openapi.NewAPIClient(openapi.NewConfiguration()).DefaultApi.DataGet(context.Background()).Execute()
fmt.Println(data, err)
}
will output
&{} <nil>
neither client side nor server side validate parameter.
Describe the solution you'd like
import some third library to validate data with schema.
or generate validate code with template
Describe alternatives you've considered
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with the supplied OpenAPI YAML and the generate -i openapi.yml -g go command, then inspect the generated Go client and server behavior shown in the issue. Done means value constraints such as maxLength, maximum, and required are validated on the requested generation targets, with the validation approach defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100