Skip to content

One of custom types for input path parameter possible? #138

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

You must be logged in to vote

Dealing with complex logical schemas (*Of, not, if, etc...) is not easy, though it is doable.

To make it work, you would need to instrument schema, decoder and validator separately.

Please check an example:

package main

import (
	"context"
	"encoding/json"
	"log"
	"net/http"
	"strconv"

	"github.com/swaggest/jsonschema-go"
	"github.com/swaggest/rest/web"
	swgui "github.com/swaggest/swgui/v4emb"
	"github.com/swaggest/usecase"
)

type intOrString struct {
	isUint bool
	u      uint64
	s      string
}

var (
	_ jsonschema.RawExposer = intOrString{}

	// Customization can also be achieved with other interfaces.
	//_ jsonschema.Exposer    = intOrString{}
	//_ jsonschema.Preparer   = intOrString{}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pboguslawski
Comment options

Answer selected by pboguslawski
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