mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
3.0 and 2.0 do not work, there are multiple versions and anything with a period in it sucks from my point of view, v2 and v3 feel much better from a DX perspective.
71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v3
|
|
|
|
import (
|
|
"github.com/pb33f/libopenapi/datamodel/high/base"
|
|
low "github.com/pb33f/libopenapi/datamodel/low/v3"
|
|
)
|
|
|
|
type Operation struct {
|
|
Tags []string
|
|
Summary string
|
|
Description string
|
|
ExternalDocs *base.ExternalDoc
|
|
OperationId string
|
|
Parameters []*Parameter
|
|
RequestBody *RequestBody
|
|
Responses *Responses
|
|
Callbacks map[string]*Callback
|
|
Deprecated bool
|
|
Security *SecurityRequirement
|
|
Servers []*Server
|
|
Extensions map[string]any
|
|
low *low.Operation
|
|
}
|
|
|
|
func NewOperation(operation *low.Operation) *Operation {
|
|
o := new(Operation)
|
|
o.low = operation
|
|
var tags []string
|
|
if !operation.Tags.IsEmpty() {
|
|
for i := range operation.Tags.Value {
|
|
tags = append(tags, operation.Tags.Value[i].Value)
|
|
}
|
|
}
|
|
o.Tags = tags
|
|
o.Summary = operation.Summary.Value
|
|
o.Description = operation.Description.Value
|
|
if !operation.ExternalDocs.IsEmpty() {
|
|
o.ExternalDocs = base.NewExternalDoc(operation.ExternalDocs.Value)
|
|
}
|
|
o.OperationId = operation.OperationId.Value
|
|
if !operation.Parameters.IsEmpty() {
|
|
params := make([]*Parameter, len(operation.Parameters.Value))
|
|
for i := range operation.Parameters.Value {
|
|
params[i] = NewParameter(operation.Parameters.Value[i].Value)
|
|
}
|
|
o.Parameters = params
|
|
}
|
|
if !operation.RequestBody.IsEmpty() {
|
|
o.RequestBody = NewRequestBody(operation.RequestBody.Value)
|
|
}
|
|
if !operation.Responses.IsEmpty() {
|
|
o.Responses = NewResponses(operation.Responses.Value)
|
|
}
|
|
if !operation.Security.IsEmpty() {
|
|
o.Security = NewSecurityRequirement(operation.Security.Value)
|
|
}
|
|
var servers []*Server
|
|
for i := range operation.Servers.Value {
|
|
servers = append(servers, NewServer(operation.Servers.Value[i].Value))
|
|
}
|
|
o.Servers = servers
|
|
return o
|
|
}
|
|
|
|
func (o *Operation) GoLow() *low.Operation {
|
|
return o.low
|
|
}
|