Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Embedded structs or pointer to structs fails #192

Open
SahilAgrawal-Druva opened this issue Feb 19, 2025 · 0 comments
Open

Embedded structs or pointer to structs fails #192

SahilAgrawal-Druva opened this issue Feb 19, 2025 · 0 comments

Comments

@SahilAgrawal-Druva
Copy link

SahilAgrawal-Druva commented Feb 19, 2025

Request Struct looks like below

// RequestStruct is the request schema for Create
// swagger:parameters CreateRequestType
type CreateRequest struct {
	// in: path
	// required: true
	// type: string
	// maxLength: 32
	// pattern: ^[a-zA-Z0-9_]+$
	Consumer string `json:"consumer"`
	// The request body
	// required: true
	// type: object
	// in: body
	Body *CreateRequestBody `json:"body"`
}

// CreateRequestBody ...
// swagger:model CreateRequestBody
type CreateRequestBody struct {
	// type: string
	// maxLength: 32
	// required: true
	// pattern: ^[a-zA-Z0-9_]+$
	Name string `json:"name"`
	// required: true
	// type: object
	// schema:
	//	$ref: '#/definitions/CallbackConfig'
	CallbackConfig *spec.CallbackConfig `json:"callbackConfig"`
}


// CallbackConfig callback config
// swagger:model CallbackConfig
type CallbackConfig struct {
	// required: true
	// type: integer
	// format: int32
	// Enum: [1]
	Type int32 `json:"type" enums:"1"`
	// type: object
	// required: true
	HTTPConfig *HTTPConfig `json:"httpConfig"`
}

// HTTPConfig config
// swagger:model HTTPConfig
type HTTPConfig struct {
	// required: true
	// format: uri
	// type: string
	URL string `json:"url"`
	// required: false
	// type: object
	Headers *map[string]string `json:"headers,omitempty"`
	// required: false
	// type: object
	Payload *map[string]interface{} `json:"payload,omitempty"`
}

Swagger is generated using below commands, which is used for validating requests.

go:generate swagger generate spec -m -o swagger.json
go:generate swagger flatten swagger.json --with-flatten=remove-unused -o swagger.json
go:generate swagger validate swagger.json

The generated swagger is validated and correct.

used below code for validating json request

// data is object of CreateRequestBody
err := validate.AgainstSchema(schema, data, strfmt.Default)

It fails while loading the the embedded struct ie CallbackConfig in this case at line https://github.com/go-openapi/spec/blob/de3527276ef8640d6b2a2435cb0ecac3e0002041/schema_loader.go#L153

tagging @swapnilmhamane-Druva

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant