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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ service Messaging {
}
message Message {
Kind kind = 1;

// Nested enum inside a message.
enum Priority {
PRIORITY_UNSPECIFIED = 0;
LOW = 1;
MEDIUM = 2;
HIGH = 3;
}
Priority priority = 2;
}
enum Kind {
UNKNOWN_KIND = 0;
Expand Down
16 changes: 16 additions & 0 deletions cmd/protoc-gen-openapi/examples/tests/enumoptions/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ paths:
in: query
schema:
$ref: '#/components/schemas/Kind'
- name: priority
in: query
schema:
$ref: '#/components/schemas/Message_Priority'
requestBody:
content:
application/json: {}
Expand Down Expand Up @@ -85,7 +89,19 @@ components:
properties:
kind:
$ref: '#/components/schemas/Kind'
priority:
$ref: '#/components/schemas/Message_Priority'
x-fern-type-name: Message
source: tests/enumoptions/message.proto
Message_Priority:
enum:
- PRIORITY_UNSPECIFIED
- LOW
- MEDIUM
- HIGH
type: string
format: enum
x-fern-type-name: Message_Priority
source: tests/enumoptions/message.proto
tags:
- name: Messaging
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ paths:
in: query
schema:
$ref: '#/components/schemas/Kind'
- name: priority
in: query
schema:
$ref: '#/components/schemas/Message_Priority'
requestBody:
content:
application/json: {}
Expand Down Expand Up @@ -85,7 +89,19 @@ components:
properties:
kind:
$ref: '#/components/schemas/Kind'
priority:
$ref: '#/components/schemas/Message_Priority'
x-fern-type-name: Message
source: tests/enumoptions/message.proto
Message_Priority:
enum:
- PRIORITY_UNSPECIFIED
- LOW
- MEDIUM
- HIGH
type: string
format: enum
x-fern-type-name: Message_Priority
source: tests/enumoptions/message.proto
tags:
- name: Messaging
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ paths:
in: query
schema:
$ref: '#/components/schemas/Kind'
- name: priority
in: query
schema:
$ref: '#/components/schemas/Message_Priority'
requestBody:
content:
application/json: {}
Expand Down Expand Up @@ -85,7 +89,19 @@ components:
properties:
kind:
$ref: '#/components/schemas/Kind'
priority:
$ref: '#/components/schemas/Message_Priority'
x-fern-type-name: Message
source: tests/enumoptions/message.proto
Message_Priority:
enum:
- PRIORITY_UNSPECIFIED
- LOW
- MEDIUM
- HIGH
type: string
format: enum
x-fern-type-name: Message_Priority
source: tests/enumoptions/message.proto
tags:
- name: Messaging
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ paths:
in: query
schema:
$ref: '#/components/schemas/Kind'
- name: priority
in: query
schema:
$ref: '#/components/schemas/Message_Priority'
requestBody:
content:
application/json: {}
Expand Down Expand Up @@ -65,6 +69,16 @@ components:
format: enum
x-fern-type-name: Kind
source: tests/enumoptions/message.proto
Message_Priority:
enum:
- PRIORITY_UNSPECIFIED
- LOW
- MEDIUM
- HIGH
type: string
format: enum
x-fern-type-name: Message_Priority
source: tests/enumoptions/message.proto
google.protobuf.Any:
type: object
properties:
Expand Down Expand Up @@ -97,6 +111,8 @@ components:
properties:
kind:
$ref: '#/components/schemas/Kind'
priority:
$ref: '#/components/schemas/Message_Priority'
x-fern-type-name: tests.enumoptions.message.v1.Message
source: tests/enumoptions/message.proto
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ paths:
in: query
schema:
$ref: '#/components/schemas/Kind'
- name: priority
in: query
schema:
$ref: '#/components/schemas/Message_Priority'
requestBody:
content:
application/json: {}
Expand Down Expand Up @@ -85,7 +89,19 @@ components:
properties:
kind:
$ref: '#/components/schemas/Kind'
priority:
$ref: '#/components/schemas/Message_Priority'
x-fern-type-name: Message
source: tests/enumoptions/message.proto
Message_Priority:
enum:
- PRIORITY_UNSPECIFIED
- LOW
- MEDIUM
- HIGH
type: string
format: enum
x-fern-type-name: Message_Priority
source: tests/enumoptions/message.proto
tags:
- name: Messaging
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ paths:
in: query
schema:
$ref: '#/components/schemas/Kind'
- name: priority
in: query
schema:
$ref: '#/components/schemas/Message_Priority'
requestBody:
content:
application/json: {}
Expand Down Expand Up @@ -85,7 +89,19 @@ components:
properties:
kind:
$ref: '#/components/schemas/Kind'
priority:
$ref: '#/components/schemas/Message_Priority'
x-fern-type-name: Message
source: tests/enumoptions/message.proto
Message_Priority:
enum:
- PRIORITY_UNSPECIFIED
- LOW
- MEDIUM
- HIGH
type: string
format: enum
x-fern-type-name: Message_Priority
source: tests/enumoptions/message.proto
tags:
- name: Messaging
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -385,7 +385,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -635,7 +635,7 @@ components:
type: google.protobuf.BoolValue
bytes_value_type:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -385,7 +385,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -635,7 +635,7 @@ components:
type: google.protobuf.BoolValue
bytes_value_type:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -385,7 +385,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -635,7 +635,7 @@ components:
type: google.protobuf.BoolValue
bytes_value_type:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -385,7 +385,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -656,7 +656,7 @@ components:
type: google.protobuf.BoolValue
bytes_value_type:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -385,7 +385,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -635,7 +635,7 @@ components:
type: google.protobuf.BoolValue
bytes_value_type:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -385,7 +385,7 @@ paths:
in: query
schema:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down Expand Up @@ -635,7 +635,7 @@ components:
type: google.protobuf.BoolValue
bytes_value_type:
type: string
format: bytes
format: byte
x-fern-encoding:
proto:
type: google.protobuf.BytesValue
Expand Down
4 changes: 2 additions & 2 deletions cmd/protoc-gen-openapi/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ func (g *OpenAPIv3Generator) addWellKnownTypeSchemaToDocumentV3(d *v3.Document,
// addSchemaForEnumsToDocumentV3 adds enum schemas to the document
func (g *OpenAPIv3Generator) addSchemaForEnumsToDocumentV3(d *v3.Document, enums []*protogen.Enum, filename string) {
for _, enum := range enums {
enumName := string(enum.Desc.Name())
enumName := g.reflect.getEnumName(enum.Desc)
enumSchema := g.createEnumSchema(enumName, enum.Desc.Values())
g.addSchemaToDocumentV3(d, &v3.NamedSchemaOrReference{
Name: enumName,
Expand All @@ -883,7 +883,7 @@ func (g *OpenAPIv3Generator) addSchemasForMessagesToDocumentV3(d *v3.Document, m
// Skip map entries and enums since they are handled separately
if len(message.Enums) > 0 {
for _, enum := range message.Enums {
enumName := string(enum.Desc.Name())
enumName := g.reflect.getEnumName(enum.Desc)
enumSchema := g.createEnumSchema(enumName, enum.Desc.Values())
g.addSchemaToDocumentV3(d, &v3.NamedSchemaOrReference{
Name: enumName,
Expand Down
4 changes: 4 additions & 0 deletions cmd/protoc-gen-openapi/generator/reflector.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (r *OpenAPIv3Reflector) getMessageName(message protoreflect.MessageDescript
return prefix + string(message.Name())
}

func (r *OpenAPIv3Reflector) getEnumName(enum protoreflect.EnumDescriptor) string {
return wk.GetEnumName(enum)
}

func (r *OpenAPIv3Reflector) formatMessageName(message protoreflect.MessageDescriptor) string {
typeName := r.fullMessageTypeName(message)

Expand Down
Loading
Loading