Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: marshal pathItem and operation extentions #1269

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Changes from 2 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
68 changes: 68 additions & 0 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,40 @@
Common OpenAPICommon `json:"-" yaml:",inline"`
}

func (s *PathItem) MarshalJSON() ([]byte, error) {
type Alias PathItem
originalJSON, err := json.Marshal(Alias(*s))
if err != nil {
return nil, err
}

d := jx.DecodeBytes(originalJSON)

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / test (386, ubuntu-latest)

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest, -race)

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest)

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, macos-latest)

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / test

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: jx

Check failure on line 337 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, windows-latest)

undefined: jx
e := jx.Encoder{}

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / test (386, ubuntu-latest)

undefined: jx

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest, -race)

undefined: jx

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest)

undefined: jx

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: jx

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, macos-latest)

undefined: jx

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / test

undefined: jx

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: jx

Check failure on line 338 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, windows-latest)

undefined: jx

e.ObjStart()
if err := d.Obj(func(d *jx.Decoder, key string) error {

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / test (386, ubuntu-latest)

undefined: jx

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest, -race)

undefined: jx

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest)

undefined: jx

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: jx

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, macos-latest)

undefined: jx

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / test

undefined: jx

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: jx

Check failure on line 341 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, windows-latest)

undefined: jx
e.FieldStart(key)
raw, err := d.Raw()
if err != nil {
return err
}

e.Raw(raw)
return nil
}); err != nil {
return nil, err
}

for extK, extV := range s.Common.Extensions {
e.FieldStart(extK)
e.Str(extV.Value)
}

e.ObjEnd()

return e.Bytes(), nil
}

// Operation describes a single API operation on a path.
//
// See https://spec.openapis.org/oas/v3.1.0#operation-object.
Expand Down Expand Up @@ -381,6 +415,40 @@
Common OpenAPICommon `json:"-" yaml:",inline"`
}

func (s *Operation) MarshalJSON() ([]byte, error) {
type Alias Operation
originalJSON, err := json.Marshal(Alias(*s))
if err != nil {
return nil, err
}

d := jx.DecodeBytes(originalJSON)

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / test (386, ubuntu-latest)

undefined: jx

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest, -race)

undefined: jx

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest)

undefined: jx

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: jx

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, macos-latest)

undefined: jx

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / test

undefined: jx

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: jx

Check failure on line 425 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, windows-latest)

undefined: jx
e := jx.Encoder{}

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / test (386, ubuntu-latest)

undefined: jx

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest, -race)

undefined: jx

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest)

undefined: jx

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: jx

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, macos-latest)

undefined: jx

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / test

undefined: jx

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: jx

Check failure on line 426 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, windows-latest)

undefined: jx

e.ObjStart()
if err := d.Obj(func(d *jx.Decoder, key string) error {

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / test (386, ubuntu-latest)

undefined: jx

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest, -race)

undefined: jx

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest)

undefined: jx

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: jx

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, macos-latest)

undefined: jx

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / test

undefined: jx

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: jx

Check failure on line 429 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, windows-latest)

undefined: jx
e.FieldStart(key)
raw, err := d.Raw()
if err != nil {
return err
}
log.Info(string(raw))

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / test (386, ubuntu-latest)

undefined: log

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest, -race)

undefined: log

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, ubuntu-latest)

undefined: log

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: log) (typecheck)

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, macos-latest)

undefined: log

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / test

undefined: log

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: log

Check failure on line 435 in spec.go

View workflow job for this annotation

GitHub Actions / test (amd64, windows-latest)

undefined: log
tdakkota marked this conversation as resolved.
Show resolved Hide resolved
e.Raw(raw)
return nil
}); err != nil {
return nil, err
}

for extK, extV := range s.Common.Extensions {
e.FieldStart(extK)
e.Str(extV.Value)
}

e.ObjEnd()

return e.Bytes(), nil
}

// ExternalDocumentation describes a reference to external resource for extended documentation.
//
// See https://spec.openapis.org/oas/v3.1.0#external-documentation-object.
Expand Down
Loading