Skip to content

Commit 3ffeaba

Browse files
authored
All descriptions defined in the OpenAPI document are generated (#213)
1 parent d29fd40 commit 3ffeaba

File tree

5 files changed

+75
-24
lines changed

5 files changed

+75
-24
lines changed

Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/CommentExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ extension TypedParameter {
154154
/// - parent: The parent type of the parameter.
155155
func docComment(parent: TypeName) -> Comment? {
156156
parent.docCommentWithUserDescription(
157-
nil,
157+
parameter.description,
158158
subPath: "\(parameter.location.rawValue)/\(parameter.name)"
159159
)
160160
}

Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseHeader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension TypesFileTranslator {
2727
parent: TypeName
2828
) throws -> PropertyBlueprint {
2929
let comment = parent.docCommentWithUserDescription(
30-
nil,
30+
header.header.description,
3131
subPath: header.name
3232
)
3333
return .init(

Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ paths:
210210
components:
211211
headers:
212212
TracingHeader:
213+
description: A description here.
213214
required: false
214215
schema:
215216
type: string
@@ -426,6 +427,7 @@ components:
426427
description: Bad request
427428
headers:
428429
X-Reason:
430+
description: A description here.
429431
schema:
430432
type: string
431433
content:
@@ -446,6 +448,7 @@ components:
446448
type: object
447449
properties:
448450
name:
451+
description: "Pet name"
449452
type: string
450453
kind:
451454
$ref: '#/components/schemas/PetKind'

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ public enum Components {
640640
@frozen public enum UpdatePetRequest: Sendable, Equatable, Hashable {
641641
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json`.
642642
public struct jsonPayload: Codable, Equatable, Hashable, Sendable {
643+
/// Pet name
644+
///
643645
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json/name`.
644646
public var name: Swift.String?
645647
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json/kind`.
@@ -649,7 +651,7 @@ public enum Components {
649651
/// Creates a new `jsonPayload`.
650652
///
651653
/// - Parameters:
652-
/// - name:
654+
/// - name: Pet name
653655
/// - kind:
654656
/// - tag:
655657
public init(
@@ -676,12 +678,14 @@ public enum Components {
676678
public struct ErrorBadRequest: Sendable, Equatable, Hashable {
677679
/// - Remark: Generated from `#/components/responses/ErrorBadRequest/headers`.
678680
public struct Headers: Sendable, Equatable, Hashable {
681+
/// A description here.
682+
///
679683
/// - Remark: Generated from `#/components/responses/ErrorBadRequest/headers/X-Reason`.
680684
public var X_Reason: Swift.String?
681685
/// Creates a new `Headers`.
682686
///
683687
/// - Parameters:
684-
/// - X_Reason:
688+
/// - X_Reason: A description here.
685689
public init(X_Reason: Swift.String? = nil) { self.X_Reason = X_Reason }
686690
}
687691
/// Received HTTP response headers
@@ -720,6 +724,8 @@ public enum Components {
720724
}
721725
/// Types generated from the `#/components/headers` section of the OpenAPI document.
722726
public enum Headers {
727+
/// A description here.
728+
///
723729
/// - Remark: Generated from `#/components/headers/TracingHeader`.
724730
public typealias TracingHeader = Swift.String
725731
}
@@ -744,6 +750,8 @@ public enum Operations {
744750
public var path: Operations.listPets.Input.Path
745751
/// - Remark: Generated from `#/paths/pets/GET/query`.
746752
public struct Query: Sendable, Equatable, Hashable {
753+
/// How many items to return at one time (max 100)
754+
///
747755
/// - Remark: Generated from `#/paths/pets/GET/query/limit`.
748756
public var limit: Swift.Int32?
749757
/// - Remark: Generated from `#/paths/pets/GET/query/habitat`.
@@ -814,15 +822,17 @@ public enum Operations {
814822
.feedsPayloadPayload]
815823
/// - Remark: Generated from `#/paths/pets/GET/query/feeds`.
816824
public var feeds: Operations.listPets.Input.Query.feedsPayload?
825+
/// Supply this parameter to filter pets born since the provided date.
826+
///
817827
/// - Remark: Generated from `#/paths/pets/GET/query/since`.
818828
public var since: Components.Parameters.query_born_since?
819829
/// Creates a new `Query`.
820830
///
821831
/// - Parameters:
822-
/// - limit:
832+
/// - limit: How many items to return at one time (max 100)
823833
/// - habitat:
824834
/// - feeds:
825-
/// - since:
835+
/// - since: Supply this parameter to filter pets born since the provided date.
826836
public init(
827837
limit: Swift.Int32? = nil,
828838
habitat: Operations.listPets.Input.Query.habitatPayload? = nil,
@@ -838,12 +848,14 @@ public enum Operations {
838848
public var query: Operations.listPets.Input.Query
839849
/// - Remark: Generated from `#/paths/pets/GET/header`.
840850
public struct Headers: Sendable, Equatable, Hashable {
851+
/// Request identifier
852+
///
841853
/// - Remark: Generated from `#/paths/pets/GET/header/My-Request-UUID`.
842854
public var My_Request_UUID: Swift.String?
843855
/// Creates a new `Headers`.
844856
///
845857
/// - Parameters:
846-
/// - My_Request_UUID:
858+
/// - My_Request_UUID: Request identifier
847859
public init(My_Request_UUID: Swift.String? = nil) {
848860
self.My_Request_UUID = My_Request_UUID
849861
}
@@ -884,15 +896,19 @@ public enum Operations {
884896
public struct Ok: Sendable, Equatable, Hashable {
885897
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers`.
886898
public struct Headers: Sendable, Equatable, Hashable {
899+
/// Response identifier
900+
///
887901
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Response-UUID`.
888902
public var My_Response_UUID: Swift.String
903+
/// A description here.
904+
///
889905
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Tracing-Header`.
890906
public var My_Tracing_Header: Components.Headers.TracingHeader?
891907
/// Creates a new `Headers`.
892908
///
893909
/// - Parameters:
894-
/// - My_Response_UUID:
895-
/// - My_Tracing_Header:
910+
/// - My_Response_UUID: Response identifier
911+
/// - My_Tracing_Header: A description here.
896912
public init(
897913
My_Response_UUID: Swift.String,
898914
My_Tracing_Header: Components.Headers.TracingHeader? = nil
@@ -986,12 +1002,14 @@ public enum Operations {
9861002
public var query: Operations.createPet.Input.Query
9871003
/// - Remark: Generated from `#/paths/pets/POST/header`.
9881004
public struct Headers: Sendable, Equatable, Hashable {
1005+
/// A description here.
1006+
///
9891007
/// - Remark: Generated from `#/paths/pets/POST/header/X-Extra-Arguments`.
9901008
public var X_Extra_Arguments: Components.Schemas.CodeError?
9911009
/// Creates a new `Headers`.
9921010
///
9931011
/// - Parameters:
994-
/// - X_Extra_Arguments:
1012+
/// - X_Extra_Arguments: A description here.
9951013
public init(X_Extra_Arguments: Components.Schemas.CodeError? = nil) {
9961014
self.X_Extra_Arguments = X_Extra_Arguments
9971015
}
@@ -1035,12 +1053,14 @@ public enum Operations {
10351053
public struct Created: Sendable, Equatable, Hashable {
10361054
/// - Remark: Generated from `#/paths/pets/POST/responses/201/headers`.
10371055
public struct Headers: Sendable, Equatable, Hashable {
1056+
/// A description here.
1057+
///
10381058
/// - Remark: Generated from `#/paths/pets/POST/responses/201/headers/X-Extra-Arguments`.
10391059
public var X_Extra_Arguments: Components.Schemas.CodeError?
10401060
/// Creates a new `Headers`.
10411061
///
10421062
/// - Parameters:
1043-
/// - X_Extra_Arguments:
1063+
/// - X_Extra_Arguments: A description here.
10441064
public init(X_Extra_Arguments: Components.Schemas.CodeError? = nil) {
10451065
self.X_Extra_Arguments = X_Extra_Arguments
10461066
}
@@ -1376,12 +1396,14 @@ public enum Operations {
13761396
public struct Input: Sendable, Equatable, Hashable {
13771397
/// - Remark: Generated from `#/paths/pets/{petId}/PATCH/path`.
13781398
public struct Path: Sendable, Equatable, Hashable {
1399+
/// Id of the pet
1400+
///
13791401
/// - Remark: Generated from `#/paths/pets/{petId}/PATCH/path/petId`.
13801402
public var petId: Swift.Int64
13811403
/// Creates a new `Path`.
13821404
///
13831405
/// - Parameters:
1384-
/// - petId:
1406+
/// - petId: Id of the pet
13851407
public init(petId: Swift.Int64) { self.petId = petId }
13861408
}
13871409
public var path: Operations.updatePet.Input.Path
@@ -1518,12 +1540,14 @@ public enum Operations {
15181540
public struct Input: Sendable, Equatable, Hashable {
15191541
/// - Remark: Generated from `#/paths/pets/{petId}/avatar/PUT/path`.
15201542
public struct Path: Sendable, Equatable, Hashable {
1543+
/// The id of the pet to retrieve
1544+
///
15211545
/// - Remark: Generated from `#/paths/pets/{petId}/avatar/PUT/path/petId`.
15221546
public var petId: Components.Parameters.path_petId
15231547
/// Creates a new `Path`.
15241548
///
15251549
/// - Parameters:
1526-
/// - petId:
1550+
/// - petId: The id of the pet to retrieve
15271551
public init(petId: Components.Parameters.path_petId) { self.petId = petId }
15281552
}
15291553
public var path: Operations.uploadAvatarForPet.Input.Path

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore_FF_MultipleContentTypes/Types.swift

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ public enum Components {
590590
@frozen public enum UpdatePetRequest: Sendable, Equatable, Hashable {
591591
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json`.
592592
public struct jsonPayload: Codable, Equatable, Hashable, Sendable {
593+
/// Pet name
594+
///
593595
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json/name`.
594596
public var name: Swift.String?
595597
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json/kind`.
@@ -599,7 +601,7 @@ public enum Components {
599601
/// Creates a new `jsonPayload`.
600602
///
601603
/// - Parameters:
602-
/// - name:
604+
/// - name: Pet name
603605
/// - kind:
604606
/// - tag:
605607
public init(
@@ -626,12 +628,14 @@ public enum Components {
626628
public struct ErrorBadRequest: Sendable, Equatable, Hashable {
627629
/// - Remark: Generated from `#/components/responses/ErrorBadRequest/headers`.
628630
public struct Headers: Sendable, Equatable, Hashable {
631+
/// A description here.
632+
///
629633
/// - Remark: Generated from `#/components/responses/ErrorBadRequest/headers/X-Reason`.
630634
public var X_hyphen_Reason: Swift.String?
631635
/// Creates a new `Headers`.
632636
///
633637
/// - Parameters:
634-
/// - X_hyphen_Reason:
638+
/// - X_hyphen_Reason: A description here.
635639
public init(X_hyphen_Reason: Swift.String? = nil) {
636640
self.X_hyphen_Reason = X_hyphen_Reason
637641
}
@@ -672,6 +676,8 @@ public enum Components {
672676
}
673677
/// Types generated from the `#/components/headers` section of the OpenAPI document.
674678
public enum Headers {
679+
/// A description here.
680+
///
675681
/// - Remark: Generated from `#/components/headers/TracingHeader`.
676682
public typealias TracingHeader = Swift.String
677683
}
@@ -696,6 +702,8 @@ public enum Operations {
696702
public var path: Operations.listPets.Input.Path
697703
/// - Remark: Generated from `#/paths/pets/GET/query`.
698704
public struct Query: Sendable, Equatable, Hashable {
705+
/// How many items to return at one time (max 100)
706+
///
699707
/// - Remark: Generated from `#/paths/pets/GET/query/limit`.
700708
public var limit: Swift.Int32?
701709
/// - Remark: Generated from `#/paths/pets/GET/query/habitat`.
@@ -724,15 +732,17 @@ public enum Operations {
724732
.feedsPayloadPayload]
725733
/// - Remark: Generated from `#/paths/pets/GET/query/feeds`.
726734
public var feeds: Operations.listPets.Input.Query.feedsPayload?
735+
/// Supply this parameter to filter pets born since the provided date.
736+
///
727737
/// - Remark: Generated from `#/paths/pets/GET/query/since`.
728738
public var since: Components.Parameters.query_period_born_hyphen_since?
729739
/// Creates a new `Query`.
730740
///
731741
/// - Parameters:
732-
/// - limit:
742+
/// - limit: How many items to return at one time (max 100)
733743
/// - habitat:
734744
/// - feeds:
735-
/// - since:
745+
/// - since: Supply this parameter to filter pets born since the provided date.
736746
public init(
737747
limit: Swift.Int32? = nil,
738748
habitat: Operations.listPets.Input.Query.habitatPayload? = nil,
@@ -748,12 +758,14 @@ public enum Operations {
748758
public var query: Operations.listPets.Input.Query
749759
/// - Remark: Generated from `#/paths/pets/GET/header`.
750760
public struct Headers: Sendable, Equatable, Hashable {
761+
/// Request identifier
762+
///
751763
/// - Remark: Generated from `#/paths/pets/GET/header/My-Request-UUID`.
752764
public var My_hyphen_Request_hyphen_UUID: Swift.String?
753765
/// Creates a new `Headers`.
754766
///
755767
/// - Parameters:
756-
/// - My_hyphen_Request_hyphen_UUID:
768+
/// - My_hyphen_Request_hyphen_UUID: Request identifier
757769
public init(My_hyphen_Request_hyphen_UUID: Swift.String? = nil) {
758770
self.My_hyphen_Request_hyphen_UUID = My_hyphen_Request_hyphen_UUID
759771
}
@@ -794,15 +806,19 @@ public enum Operations {
794806
public struct Ok: Sendable, Equatable, Hashable {
795807
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers`.
796808
public struct Headers: Sendable, Equatable, Hashable {
809+
/// Response identifier
810+
///
797811
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Response-UUID`.
798812
public var My_hyphen_Response_hyphen_UUID: Swift.String
813+
/// A description here.
814+
///
799815
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Tracing-Header`.
800816
public var My_hyphen_Tracing_hyphen_Header: Components.Headers.TracingHeader?
801817
/// Creates a new `Headers`.
802818
///
803819
/// - Parameters:
804-
/// - My_hyphen_Response_hyphen_UUID:
805-
/// - My_hyphen_Tracing_hyphen_Header:
820+
/// - My_hyphen_Response_hyphen_UUID: Response identifier
821+
/// - My_hyphen_Tracing_hyphen_Header: A description here.
806822
public init(
807823
My_hyphen_Response_hyphen_UUID: Swift.String,
808824
My_hyphen_Tracing_hyphen_Header: Components.Headers.TracingHeader? = nil
@@ -896,12 +912,14 @@ public enum Operations {
896912
public var query: Operations.createPet.Input.Query
897913
/// - Remark: Generated from `#/paths/pets/POST/header`.
898914
public struct Headers: Sendable, Equatable, Hashable {
915+
/// A description here.
916+
///
899917
/// - Remark: Generated from `#/paths/pets/POST/header/X-Extra-Arguments`.
900918
public var X_hyphen_Extra_hyphen_Arguments: Components.Schemas.CodeError?
901919
/// Creates a new `Headers`.
902920
///
903921
/// - Parameters:
904-
/// - X_hyphen_Extra_hyphen_Arguments:
922+
/// - X_hyphen_Extra_hyphen_Arguments: A description here.
905923
public init(X_hyphen_Extra_hyphen_Arguments: Components.Schemas.CodeError? = nil) {
906924
self.X_hyphen_Extra_hyphen_Arguments = X_hyphen_Extra_hyphen_Arguments
907925
}
@@ -945,12 +963,14 @@ public enum Operations {
945963
public struct Created: Sendable, Equatable, Hashable {
946964
/// - Remark: Generated from `#/paths/pets/POST/responses/201/headers`.
947965
public struct Headers: Sendable, Equatable, Hashable {
966+
/// A description here.
967+
///
948968
/// - Remark: Generated from `#/paths/pets/POST/responses/201/headers/X-Extra-Arguments`.
949969
public var X_hyphen_Extra_hyphen_Arguments: Components.Schemas.CodeError?
950970
/// Creates a new `Headers`.
951971
///
952972
/// - Parameters:
953-
/// - X_hyphen_Extra_hyphen_Arguments:
973+
/// - X_hyphen_Extra_hyphen_Arguments: A description here.
954974
public init(
955975
X_hyphen_Extra_hyphen_Arguments: Components.Schemas.CodeError? = nil
956976
) { self.X_hyphen_Extra_hyphen_Arguments = X_hyphen_Extra_hyphen_Arguments }
@@ -1294,12 +1314,14 @@ public enum Operations {
12941314
public struct Input: Sendable, Equatable, Hashable {
12951315
/// - Remark: Generated from `#/paths/pets/{petId}/PATCH/path`.
12961316
public struct Path: Sendable, Equatable, Hashable {
1317+
/// Id of the pet
1318+
///
12971319
/// - Remark: Generated from `#/paths/pets/{petId}/PATCH/path/petId`.
12981320
public var petId: Swift.Int64
12991321
/// Creates a new `Path`.
13001322
///
13011323
/// - Parameters:
1302-
/// - petId:
1324+
/// - petId: Id of the pet
13031325
public init(petId: Swift.Int64) { self.petId = petId }
13041326
}
13051327
public var path: Operations.updatePet.Input.Path
@@ -1436,12 +1458,14 @@ public enum Operations {
14361458
public struct Input: Sendable, Equatable, Hashable {
14371459
/// - Remark: Generated from `#/paths/pets/{petId}/avatar/PUT/path`.
14381460
public struct Path: Sendable, Equatable, Hashable {
1461+
/// The id of the pet to retrieve
1462+
///
14391463
/// - Remark: Generated from `#/paths/pets/{petId}/avatar/PUT/path/petId`.
14401464
public var petId: Components.Parameters.path_period_petId
14411465
/// Creates a new `Path`.
14421466
///
14431467
/// - Parameters:
1444-
/// - petId:
1468+
/// - petId: The id of the pet to retrieve
14451469
public init(petId: Components.Parameters.path_period_petId) { self.petId = petId }
14461470
}
14471471
public var path: Operations.uploadAvatarForPet.Input.Path

0 commit comments

Comments
 (0)