Skip to content

How can I add example for the whole struct #103

Closed Answered by vearutop
Keithwachira asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, please check an example.

package main

import (
	"fmt"
	"net/http"

	"github.com/swaggest/jsonschema-go"
	"github.com/swaggest/openapi-go/openapi31"
)

type p3 struct {
	Name    string `json:"name"`
	Message string `json:"message"`
}

func (p p3) PrepareJSONSchema(schema *jsonschema.Schema) error {
	// Preparer can add and example to the schema.
	schema.WithExamples(p3{
		Name:    "itachi",
		Message: "sasuki",
	})

	return nil
}

func main() {
	reflector := openapi31.Reflector{}
	reflector.Spec = &openapi31.Spec{Openapi: "3.0.3"}
	reflector.Spec.Info.
		WithTitle("Hello World").
		WithVersion("1.2.3")

	// Field examples end up as individual entries for respective properties.
	type p1 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Keithwachira
Comment options

@vearutop
Comment options

@Keithwachira
Comment options

Answer selected by vearutop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants