Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Generate models from official docker specification #2494

Closed
insidieux opened this issue Jan 22, 2021 · 1 comment · Fixed by #2497
Closed

Generate models from official docker specification #2494

insidieux opened this issue Jan 22, 2021 · 1 comment · Fixed by #2497
Labels
bug model Related to swagger generate model command pending PR

Comments

@insidieux
Copy link

insidieux commented Jan 22, 2021

Problem statement

Generation models for official docker swagger specification is writing models with error in validation methods.

Swagger specification

https://raw.githubusercontent.com/docker/engine/v19.03.13/api/swagger.yaml

Steps to reproduce

swagger generate model \
    -f https://raw.githubusercontent.com/docker/engine/v19.03.13/api/swagger.yaml \
    --target internal/generated

Example

Definition https://raw.githubusercontent.com/docker/engine/v19.03.13/api/swagger.yaml#/definitions/PortMap

Part of generated code for definition

// swagger:model PortMap
type PortMap map[string]*[]PortBinding

// Validate validates this port map
func (m PortMap) Validate(formats strfmt.Registry) error {
	var res []error
	for k := range m {
		if err := validate.Required(k, "body", m[k]); err != nil {
			return err
		}
		for i := 0; i < len(m[k]); i++ {
			if err := m[k][i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName(k + "." + strconv.Itoa(i))
				}
				return err
			}
		}
	}
	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

We can't get len(m[k]) cause of pointer to slice.
And we can't get m[k][i] cause pointer does not support indexing.
So build will be failed.

Environment

swagger version: v0.26.0
go version: 1.15.6
OS: darwin/linux

@fredbi fredbi added doc bug model Related to swagger generate model command and removed doc labels Jan 23, 2021
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 23, 2021
…ointer,

regardless of the x-nullable directive

* fixes go-swagger#2494

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 23, 2021
…ointer,

regardless of the x-nullable directive

* fixes go-swagger#2494

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit that referenced this issue Jan 23, 2021
…ointer, (#2497)

regardless of the x-nullable directive

* fixes #2494

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@insidieux
Copy link
Author

@fredbi can you make a release/tag 0.26.1? we need docker image with new version and with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug model Related to swagger generate model command pending PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants