Repository: swaggest/openapi-go
Pull request #26 (2021-07-29 15:57:02)

Add support for deprecated properties with named schemas

github-actions[bot]: ### Lines Of Code

| Language | Files |   Lines    |   Code    | Comments |  Blanks  | Complexity |     Bytes     |
|----------|-------|------------|-----------|----------|----------|------------|---------------|
| Go       | 6     | 1196 (+13) | 899 (+11) | 52       | 245 (+2) | 292 (+2)   | 26.8K (+290B) |
| JSON     | 6     | 2205       | 2205      | 0        | 0        | 0          | 49.8K (+72B)  |
| YAML     | 6     | 306 (-1)   | 266 (-1)  | 25       | 15       | 0          | 8.9K (-14B)   |
<!-- Sticky Pull Request CommentLOC -->
github-actions[bot]: ### Exported API Changes Report

<pre>
# summary
Inferred base version: v0.2.11
Suggested version: v0.2.12
</pre>
<!-- Sticky Pull Request Commentgorelease -->
github-actions[bot]: ### Unit Test Coverage
total:	(statements)	45.7%
<details><summary>Coverage diff with base branch</summary>

```diff
554c554
< github.com/swaggest/openapi-go/openapi3/jsonschema.go	FromJSONSchema	79.7%
---
> github.com/swaggest/openapi-go/openapi3/jsonschema.go	FromJSONSchema	79.3%
```
</details>
<!-- Sticky Pull Request Commentunit-test -->

Patch:
diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml
index 49dba7b..445ad3e 100644
--- a/.github/workflows/gorelease.yml
+++ b/.github/workflows/gorelease.yml
@@ -27,13 +27,12 @@ jobs:
         id: gorelease
         run: |
           test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
-          gorelease
-          OUTPUT=$(gorelease)
+          OUTPUT=$(gorelease || exit 0)
           OUTPUT="${OUTPUT//'%'/'%25'}"
           OUTPUT="${OUTPUT//$'\n'/'%0A'}"
           OUTPUT="${OUTPUT//$'\r'/'%0D'}"
           echo "::set-output name=report::$OUTPUT"
-      - name: Comment Gorelase Report
+      - name: Comment Report
         uses: marocchino/sticky-pull-request-comment@v2
         with:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -41,6 +40,6 @@ jobs:
           message: |
             ### Exported API Changes Report
 
-            ```
+            <pre>
             ${{ steps.gorelease.outputs.report }}
-            ```
\ No newline at end of file
+            </pre>
\ No newline at end of file
diff --git a/go.mod b/go.mod
index f6b1f7c..5e77698 100644
--- a/go.mod
+++ b/go.mod
@@ -3,10 +3,10 @@ module github.com/swaggest/openapi-go
 go 1.13
 
 require (
-	github.com/bool64/dev v0.1.36
+	github.com/bool64/dev v0.1.37
 	github.com/stretchr/testify v1.7.0
 	github.com/swaggest/assertjson v1.6.6
-	github.com/swaggest/jsonschema-go v0.3.20
+	github.com/swaggest/jsonschema-go v0.3.22
 	github.com/swaggest/refl v1.0.0
 	gopkg.in/yaml.v2 v2.4.0
 )
diff --git a/go.sum b/go.sum
index dbc10b3..c298bf1 100644
--- a/go.sum
+++ b/go.sum
@@ -1,8 +1,8 @@
 github.com/bool64/dev v0.1.17/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
 github.com/bool64/dev v0.1.25/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
 github.com/bool64/dev v0.1.35/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
-github.com/bool64/dev v0.1.36 h1:ZUyNrmb383OeHUSjtncODyq9RSLoDpEWxHvo5yQGhis=
-github.com/bool64/dev v0.1.36/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
+github.com/bool64/dev v0.1.37 h1:/c8U4emt4xjMDx8Au+POOYo5LJIw+Mzi4e48j5CmGQo=
+github.com/bool64/dev v0.1.37/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
 github.com/bool64/shared v0.1.3 h1:gj7XZPYa1flQsCg3q9AIju+W2A1jaexK0fdFu2XtaG0=
 github.com/bool64/shared v0.1.3/go.mod h1:RF1p1Oi29ofgOvinBpetbF5mceOUP3kpMkvLbWOmtm0=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -59,8 +59,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/swaggest/assertjson v1.6.6 h1:QO//07sfx9KR6h4t/8L+I5qOWUifLnu8gblhFYwkVQM=
 github.com/swaggest/assertjson v1.6.6/go.mod h1:HNfIAKxJJkeDmtrBU01dcWvEFjhghO96gx9Eo4rRjIc=
-github.com/swaggest/jsonschema-go v0.3.20 h1:ziunzl/iu5gm7OPWI9dkLOPte4GrZIkRhQNnycL18IA=
-github.com/swaggest/jsonschema-go v0.3.20/go.mod h1:kTYngQ48oh1Wx+exL8EHTCSpheYX9JY/IgtOp9eVcZY=
+github.com/swaggest/jsonschema-go v0.3.22 h1:9tdd1vc6jF+I6Uy4lIJFshoekZJ3uOowhAS7Ed1DxLg=
+github.com/swaggest/jsonschema-go v0.3.22/go.mod h1:UMMhyRN4FIUjy6ivVycElnWq+C7ql/1+L2R0BG01LkE=
 github.com/swaggest/refl v1.0.0 h1:yAFdjLQjmFuH4FHiD+HMaDUbF4cW0PbH5uhNoN4bme4=
 github.com/swaggest/refl v1.0.0/go.mod h1:acYd5x8NNxivp+ZHdRZKJYz66n/qjo3Q9Sa/jAivljQ=
 github.com/yosuke-furukawa/json5 v0.1.2-0.20201207051438-cf7bb3f354ff/go.mod h1:sw49aWDqNdRJ6DYUtIQiaA3xyj2IL9tjeNYmX2ixwcU=
diff --git a/openapi3/jsonschema.go b/openapi3/jsonschema.go
index f00232a..0503ed6 100644
--- a/openapi3/jsonschema.go
+++ b/openapi3/jsonschema.go
@@ -186,6 +186,19 @@ func (s *SchemaOrRef) FromJSONSchema(schema jsonschema.SchemaOrBool) {
 
 	js := schema.TypeObject
 	if js.Ref != nil {
+		if deprecated, ok := js.ExtraProperties["deprecated"].(bool); ok && deprecated {
+			s.Schema = (&Schema{}).WithAllOf(
+				SchemaOrRef{
+					Schema: (&Schema{}).WithDeprecated(true),
+				},
+				SchemaOrRef{
+					SchemaReference: &SchemaReference{Ref: *js.Ref},
+				},
+			)
+
+			return
+		}
+
 		s.SchemaReference = &SchemaReference{Ref: *js.Ref}
 
 		return


Test patch:
diff --git a/openapi3/_testdata/openapi.json b/openapi3/_testdata/openapi.json
index 2e2a159..967589a 100644
--- a/openapi3/_testdata/openapi.json
+++ b/openapi3/_testdata/openapi.json
@@ -14,7 +14,7 @@
       "schema":{"type":"integer","description":"Query parameter."}
      },
      {"name":"in_path","in":"path","required":true,"schema":{"type":"integer"}},
-     {"name":"in_cookie","in":"cookie","deprecated":true,"schema":{"type":"string"}},
+     {"name":"in_cookie","in":"cookie","deprecated":true,"schema":{"type":"string","deprecated":true}},
      {"name":"in_header","in":"header","schema":{"type":"number"}}
     ],
     "responses":{
@@ -58,7 +58,7 @@
       "schema":{"type":"array","items":{"type":"string"}}
      },
      {"name":"in_path","in":"path","required":true,"schema":{"type":"integer"}},
-     {"name":"in_cookie","in":"cookie","deprecated":true,"schema":{"type":"string"}},
+     {"name":"in_cookie","in":"cookie","deprecated":true,"schema":{"type":"string","deprecated":true}},
      {"name":"in_header","in":"header","schema":{"type":"number"}},
      {"name":"uuid","in":"header","schema":{"$ref":"#/components/schemas/Openapi3TestUUID"}}
     ],
diff --git a/openapi3/_testdata/openapi_req.json b/openapi3/_testdata/openapi_req.json
index 3ffafac..3abe0bb 100644
--- a/openapi3/_testdata/openapi_req.json
+++ b/openapi3/_testdata/openapi_req.json
@@ -13,7 +13,7 @@
       "schema":{"type":"integer","description":"Query parameter."}
      },
      {"name":"in_path","in":"path","required":true,"schema":{"type":"integer"}},
-     {"name":"in_cookie","in":"cookie","deprecated":true,"schema":{"type":"string"}},
+     {"name":"in_cookie","in":"cookie","deprecated":true,"schema":{"type":"string","deprecated":true}},
      {"name":"in_header","in":"header","schema":{"type":"number"}}
     ],
     "responses":{"204":{"description":"No Content"}}
diff --git a/openapi3/_testdata/openapi_req_array.json b/openapi3/_testdata/openapi_req_array.json
index 9104a4e..5405f64 100644
--- a/openapi3/_testdata/openapi_req_array.json
+++ b/openapi3/_testdata/openapi_req_array.json
@@ -17,7 +17,7 @@
    "Openapi3TestGetReq":{
     "required":["q1","q3"],"type":"object",
     "properties":{
-     "c":{"type":"string"},"h":{"type":"number"},"p":{"type":"integer"},
+     "c":{"type":"string","deprecated":true},"h":{"type":"number"},"p":{"type":"integer"},
      "q1":{"type":"integer","description":"Query parameter."},"q3":{"type":"integer","description":"Query parameter."}
     }
    }