Skip to content
Closed
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
2 changes: 1 addition & 1 deletion refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (resolver *refResolver) expand(n node) error {
// /components are expanded only on demand (when targeted by a link)
// because expanding unused components would inject their external
// content into the final document.
if k == "components" && n.loc.Ptr == "" {
if k == "components" && n.loc.Ptr == "" && !hasDirective(obj[k]) {
continue
}
if err := resolver.expandProperty(n.loc, obj, k); err != nil {
Expand Down
16 changes: 16 additions & 0 deletions testdata/47-inline-components/input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.2
info:
title: Test
version: "0.0.1"
paths:
/:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
$inline: schemas.yml
37 changes: 37 additions & 0 deletions testdata/47-inline-components/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"components": {
"schemas": {
"Pet": {
"properties": {
"name": {
"type": "string"
}
},
"type": "object"
}
}
},
"info": {
"title": "Test",
"version": "0.0.1"
},
"openapi": "3.0.2",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
},
"description": "OK"
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions testdata/47-inline-components/schemas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
schemas:
Pet:
type: object
properties:
name:
type: string
11 changes: 11 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ func stringProp(obj map[string]any, key string) (value string, ok bool) {
value, ok = v.(string)
return
}

func hasDirective(v any) bool {
m, ok := v.(map[string]any)
if !ok {
return false
}
_, hasRef := m["$ref"]
_, hasInline := m["$inline"]
_, hasMerge := m["$merge"]
return hasRef || hasInline || hasMerge
}