Skip to content

Single Model has rogue type with no explanation #2254

@king-jam

Description

@king-jam

Problem statement

Individual model not using the same referenced model as other files.

Swagger specification

odata-v4.yaml - global models used across nearly every other model

components:
  schemas:
    context:
      description: The OData description of a payload.
      format: uri-reference
      readOnly: true
      type: string
      x-longDescription:
        The value of this property shall be the context URL that
        describes the resource according to OData-Protocol and shall be of the form
        defined in the Redfish specification.
      x-go-name: OdataContext
    count:
      description: The number of items in a collection.
      readOnly: true
      type: integer
      x-longDescription:
        The value of this property shall be an integer representing
        the number of items in a collection.
      x-go-name: OdataCount
    etag:
      description: The current ETag of the resource.
      readOnly: true
      type: string
      x-longDescription:
        The value of this property shall be a string that is defined
        by the ETag HTTP header definition in RFC7232.
      x-go-name: OdataEtag
    id:
      description: The unique identifier for a resource.
      format: uri-reference
      readOnly: true
      type: string
      x-longDescription:
        The value of this property shall be the unique identifier
        for the resource and it shall be of the form defined in the Redfish specification.
      x-go-name: OdataID
    idRef:
      additionalProperties: false
      description: A reference to a resource.
      properties:
        "@odata.id":
          $ref: "#/components/schemas/id"
      type: object
      x-longDescription:
        The value of this property shall be used for references to
        a resource.
      x-go-name: OdataIDRef
    nextLink:
      description: The URI to the resource containing the next set of partial members.
      format: uri-reference
      readOnly: true
      type: string
      x-longDescription:
        The value of this property shall be a URI to a resource,
        with the same @odata.type, containing the next set of partial members.
      x-go-name: OdataNextLink
    type:
      description: The type of a resource.
      readOnly: true
      type: string
      x-longDescription:
        The value of this property shall be a URI fragment that specifies
        the type of the resource and it shall be of the form defined in the Redfish
        specification.
      x-go-name: OdataType

ChassisCollection.yaml - sample of the import into the model with issues

...
    ChassisCollection:
      properties:
        '@odata.context':
          $ref: odata-v4.yaml#/components/schemas/context
        '@odata.etag':
          $ref: odata-v4.yaml#/components/schemas/etag
        '@odata.id':
          $ref: odata-v4.yaml#/components/schemas/id
        '@odata.type':
          $ref: odata-v4.yaml#/components/schemas/type
...

20-30 other models with similar '@odata.id' reference - no issues and same exact declaration

...
    Chassis:
      properties:
        '@odata.context':
          $ref: odata-v4.yaml#/components/schemas/context
        '@odata.etag':
          $ref: odata-v4.yaml#/components/schemas/etag
        '@odata.id':
          $ref: odata-v4.yaml#/components/schemas/id
        '@odata.type':
          $ref: odata-v4.yaml#/components/schemas/type
...

Steps to reproduce

  1. Use above models (plus some more, about 80k lines of YAML).
  2. swagger -q generate server -f jellyfish.yml --template=stratoscale -t generated (tried without stratoscale, same behavior)
  3. End up with one model with:
...
// swagger:model chassisCollection
type ChassisCollection struct {

	// at odata context
	AtOdataContext OdataContext `json:"@odata.context,omitempty"`

	// at odata etag
	AtOdataEtag OdataEtag `json:"@odata.etag,omitempty"`

	// at odata id
	// Required: true
	AtOdataID AtOdataID `json:"@odata.id"`   #### UNDEFINED MODEL NAME ####

	// at odata type
	// Required: true
	AtOdataType OdataType `json:"@odata.type"`
...

Remaining models are correct. Just a single model has that rogue type of AtOdataID when the x-go-name means it should be OdataID like all other models (and aligns with the model that is generated)

...
// swagger:model chassis
type Chassis struct {

	// at odata context
	AtOdataContext OdataContext `json:"@odata.context,omitempty"`

	// at odata etag
	AtOdataEtag OdataEtag `json:"@odata.etag,omitempty"`

	// at odata id
	// Required: true
	AtOdataID OdataID `json:"@odata.id"`       ##### THIS IS WHAT IS DESIRED ####

	// at odata type
	// Required: true
	AtOdataType OdataType `json:"@odata.type"`

Environment

swagger version: v0.23.0
go version: go1.14
OS: Ubuntu 19.10

Metadata

Metadata

Assignees

Labels

cant reproduceCan't reproduce on current mastermodelRelated to swagger generate model command

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions