Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions fixtures/enhancements/named-struct-tags-ref/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

// Package named_struct_tags exercises schemaBuilder.buildNamedStruct
// branches where a named struct referenced as a field carries a
// swagger:strfmt or swagger:type annotation that overrides its schema.
package named_struct_tags

// PhoneNumber is a named struct annotated as a strfmt. When used as a
// field type the scanner emits {type: "string", format: "phone"} via the
// strfmt branch of buildNamedStruct.
//
// Since we have added the explicit model annotation, we expect this definition
// to bubble up and appear as a $ref in the spec.
//
// swagger:strfmt phone
// swagger:model
type PhoneNumber struct {
CountryCode string
Number string
}

// LegacyCode is a named struct annotated with swagger:type so that its
// referenced schema is coerced to the declared swagger type rather than
// emitted as an object.
//
// swagger:type string
type LegacyCode struct {
Version int
}

// Contact references both tagged struct types so the scanner walks the
// buildNamedStruct strfmt and typeName branches on distinct fields.
//
// swagger:model Contact
type Contact struct {
// required: true
ID int64 `json:"id"`

Phone PhoneNumber `json:"phone"`

Code LegacyCode `json:"code"`
}
3 changes: 1 addition & 2 deletions fixtures/integration/golden/classification_responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@
],
"type": "integer",
"format": "int64",
"default": 400,
"description": "in: header"
"default": 400
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions fixtures/integration/golden/enhancements_alias_expand.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
],
"properties": {
"data": {
"description": "in: body",
"type": "object",
"required": [
"id"
Expand All @@ -29,7 +28,6 @@
"x-go-name": "Data"
},
"search": {
"description": "in: query",
"type": "string",
"x-go-name": "Search"
}
Expand All @@ -44,7 +42,6 @@
],
"properties": {
"data": {
"description": "in: body",
"type": "object",
"required": [
"id"
Expand All @@ -63,7 +60,6 @@
"x-go-name": "Data"
},
"search": {
"description": "in: query",
"type": "string",
"x-go-name": "Search"
}
Expand Down Expand Up @@ -162,7 +158,6 @@
"$ref": "#/definitions/Payload"
},
"search": {
"description": "in: query",
"type": "string",
"x-go-name": "Search"
}
Expand Down
1 change: 0 additions & 1 deletion fixtures/integration/golden/enhancements_alias_ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"$ref": "#/definitions/Payload"
},
"search": {
"description": "in: query",
"type": "string",
"x-go-name": "Search"
}
Expand Down
26 changes: 18 additions & 8 deletions fixtures/integration/golden/enhancements_allof_edges.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,22 @@
"x-go-package": "github.com/go-openapi/codescan/fixtures/enhancements/allof-edges"
},
"AllOfStdTime": {
"type": "string",
"title": "AllOfStdTime composes an allOf member that is time.Time.",
"allOf": [
{
"type": "string",
"format": "date-time"
},
{
"type": "object",
"properties": {
"label": {
"type": "string",
"x-go-name": "Label"
}
}
}
],
"x-go-package": "github.com/go-openapi/codescan/fixtures/enhancements/allof-edges"
},
"AllOfStrfmt": {
Expand Down Expand Up @@ -84,17 +98,13 @@
"type": "object",
"title": "Tagger is a non-empty named interface used as an allOf member.",
"properties": {
"Tag": {
"tag": {
"description": "Tag returns an identifier.",
"type": "string"
"type": "string",
"x-go-name": "Tag"
}
},
"x-go-package": "github.com/go-openapi/codescan/fixtures/enhancements/allof-edges"
},
"ULID": {
"description": "ULID is a named struct formatted as a swagger strfmt. Using a struct\nunderlying type exercises the strfmt branch of buildNamedAllOf for\nstruct members.",
"type": "object",
"x-go-package": "github.com/go-openapi/codescan/fixtures/enhancements/allof-edges"
}
}
}
10 changes: 6 additions & 4 deletions fixtures/integration/golden/enhancements_embedded_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@
"type": "object",
"title": "EmbedsNamedInterface embeds a non-empty, non-error named interface.",
"properties": {
"Handle": {
"handle": {
"description": "Handle is a unary method exposed as a schema property.",
"type": "string"
"type": "string",
"x-go-name": "Handle"
},
"tag": {
"type": "string",
Expand All @@ -101,9 +102,10 @@
"type": "object",
"title": "Handler is a non-empty named interface with a single exported method.",
"properties": {
"Handle": {
"handle": {
"description": "Handle is a unary method exposed as a schema property.",
"type": "string"
"type": "string",
"x-go-name": "Handle"
}
},
"x-go-package": "github.com/go-openapi/codescan/fixtures/enhancements/embedded-types"
Expand Down
9 changes: 5 additions & 4 deletions fixtures/integration/golden/enhancements_enum_docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
],
"properties": {
"channel": {
"description": "The delivery channel.\nemail ChannelEmail ChannelSMS ChannelEmail and ChannelSMS share a single spec.\npush ChannelPush ChannelPush is the push notification channel.",
"description": "The delivery channel.\nemail ChannelEmail and ChannelSMS share a single spec.\nsms ChannelSMS and ChannelSMS share a single spec.\npush ChannelPush is the push notification channel.",
"type": "string",
"enum": [
"email",
"sms",
"push"
],
"x-go-enum-desc": "email ChannelEmail ChannelSMS ChannelEmail and ChannelSMS share a single spec.\npush ChannelPush ChannelPush is the push notification channel.",
"x-go-enum-desc": "email ChannelEmail and ChannelSMS share a single spec.\nsms ChannelSMS and ChannelSMS share a single spec.\npush ChannelPush is the push notification channel.",
"x-go-name": "Channel"
},
"id": {
Expand All @@ -25,14 +26,14 @@
"x-go-name": "ID"
},
"priority": {
"description": "The priority level.\nlow PriorityLow PriorityLow is a low-priority level.\nmedium PriorityMed PriorityMed is a medium-priority level.\nhigh PriorityHigh PriorityHigh is a high-priority level.",
"description": "The priority level.\nlow PriorityLow is a low-priority level.\nmedium PriorityMed is a medium-priority level.\nhigh PriorityHigh is a high-priority level.",
"type": "string",
"enum": [
"low",
"medium",
"high"
],
"x-go-enum-desc": "low PriorityLow PriorityLow is a low-priority level.\nmedium PriorityMed PriorityMed is a medium-priority level.\nhigh PriorityHigh PriorityHigh is a high-priority level.",
"x-go-enum-desc": "low PriorityLow is a low-priority level.\nmedium PriorityMed is a medium-priority level.\nhigh PriorityHigh is a high-priority level.",
"x-go-name": "Priority"
}
},
Expand Down
77 changes: 44 additions & 33 deletions fixtures/integration/golden/enhancements_interface_methods.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"Audited": {
"type": "object",
"properties": {
"CreatedAt": {
"createdAt": {
"description": "CreatedAt is the creation timestamp.",
"type": "string",
"format": "date-time"
"format": "date-time",
"x-go-name": "CreatedAt"
},
"UpdatedAt": {
"updatedAt": {
"description": "UpdatedAt is the update timestamp.",
"type": "string",
"format": "date-time"
"format": "date-time",
"x-go-name": "UpdatedAt"
}
},
"x-go-package": "github.com/go-openapi/codescan/fixtures/enhancements/interface-methods"
Expand All @@ -22,9 +24,10 @@
"description": "Public exposes just a single scalar so we get a minimal, deterministic\ncompanion to assert the default code path.",
"type": "object",
"properties": {
"Kind": {
"kind": {
"description": "Kind names the public flavor.",
"type": "string"
"type": "string",
"x-go-name": "Kind"
}
},
"x-go-package": "github.com/go-openapi/codescan/fixtures/enhancements/interface-methods"
Expand All @@ -38,42 +41,47 @@
{
"type": "object",
"required": [
"ID"
"id"
],
"properties": {
"Bio": {
"bio": {
"description": "Bio is a nullable pointer string.",
"type": "string"
"type": "string",
"x-go-name": "Bio"
},
"Email": {
"email": {
"description": "Email is formatted as an email strfmt.",
"type": "string",
"format": "email"
"format": "email",
"x-go-name": "Email"
},
"fullName": {
"description": "Name is re-exposed as \"fullName\" in JSON.",
"type": "string",
"x-go-name": "Name"
},
"ID": {
"id": {
"description": "ID is the user identifier.",
"type": "integer",
"format": "int64",
"minimum": 1
"minimum": 1,
"x-go-name": "ID"
},
"Profile": {
"profile": {
"description": "Profile returns nested structured data.",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"x-go-name": "Profile"
},
"Tags": {
"tags": {
"description": "Tags returns the user's labels.",
"type": "array",
"items": {
"type": "string"
}
},
"fullName": {
"description": "Name is re-exposed as \"fullName\" in JSON.",
"type": "string",
"x-go-name": "Name"
},
"x-go-name": "Tags"
}
}
}
Expand All @@ -86,29 +94,32 @@
{
"type": "object",
"properties": {
"ExternalID": {
"audit": {
"description": "AuditTrail is exposed via the anonymous embedded interface.",
"type": "string",
"x-go-name": "AuditTrail"
},
"externalId": {
"description": "ExternalID is tagged as uuid so the anon-method strfmt branch\nis exercised.",
"type": "string",
"format": "uuid"
"format": "uuid",
"x-go-name": "ExternalID"
},
"Revision": {
"revision": {
"description": "Revision is a nullable pointer return for x-nullable coverage.",
"type": "integer",
"format": "int64"
},
"audit": {
"description": "AuditTrail is exposed via the anonymous embedded interface.",
"type": "string",
"x-go-name": "AuditTrail"
"format": "int64",
"x-go-name": "Revision"
}
}
},
{
"type": "object",
"properties": {
"Kind": {
"kind": {
"description": "Kind names the root flavor.",
"type": "string"
"type": "string",
"x-go-name": "Kind"
}
}
}
Expand Down
Loading
Loading