From ba08eea8ee4a662540e0ec43c98ca821ba1540fb Mon Sep 17 00:00:00 2001 From: Casey Waldren Date: Tue, 13 Aug 2024 14:37:44 -0700 Subject: [PATCH] refactor: use sdk-meta for quickstart ordering --- go.mod | 2 +- go.sum | 2 + internal/quickstart/choose_sdk.go | 33 +----- .../openapi3/testdata/circularRef/base.yml | 16 +++ .../openapi3/testdata/circularRef/other.yml | 10 ++ .../testdata/recursiveRef/components/Bar.yml | 2 + .../testdata/recursiveRef/components/Cat.yml | 4 + .../testdata/recursiveRef/components/Foo.yml | 4 + .../recursiveRef/components/Foo/Foo2.yml | 4 + .../recursiveRef/components/models/error.yaml | 2 + .../testdata/recursiveRef/issue615.yml | 60 ++++++++++ .../testdata/recursiveRef/openapi.yml | 33 ++++++ .../recursiveRef/openapi.yml.internalized.yml | 110 ++++++++++++++++++ .../recursiveRef/parameters/number.yml | 4 + .../testdata/recursiveRef/paths/foo.yml | 15 +++ .../sdk-meta/api/sdkmeta/data/popularity.json | 25 ++++ .../sdk-meta/api/sdkmeta/data/releases.json | 8 +- .../sdk-meta/api/sdkmeta/sdkmeta.go | 7 ++ vendor/modules.txt | 2 +- 19 files changed, 310 insertions(+), 33 deletions(-) create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/base.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/other.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Bar.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Cat.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo/Foo2.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/models/error.yaml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/issue615.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml.internalized.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/parameters/number.yml create mode 100644 vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/paths/foo.yml create mode 100644 vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/popularity.json diff --git a/go.mod b/go.mod index af8e532d..6f65e4ac 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/uuid v1.6.0 github.com/iancoleman/strcase v0.3.0 github.com/launchdarkly/api-client-go/v14 v14.0.0 - github.com/launchdarkly/sdk-meta/api v0.1.1 + github.com/launchdarkly/sdk-meta/api v0.2.0 github.com/mitchellh/go-homedir v1.1.0 github.com/muesli/reflow v0.3.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c diff --git a/go.sum b/go.sum index 84778c44..30914499 100644 --- a/go.sum +++ b/go.sum @@ -168,6 +168,8 @@ github.com/launchdarkly/api-client-go/v14 v14.0.0 h1:fZfi5zKwgjpaOgK4NKcU5mJT2C8 github.com/launchdarkly/api-client-go/v14 v14.0.0/go.mod h1:K7ejD5nn9ar94p/5qrQ0t9iJygdIQyH70U9M9rYvw5Y= github.com/launchdarkly/sdk-meta/api v0.1.1 h1:B9UaOFTDGQSDzbSTwqiBmaTN3xDfrlIu1JQ9LCs2UiA= github.com/launchdarkly/sdk-meta/api v0.1.1/go.mod h1:vXfR0z4XBz49IYT/2GDEza+Iat3PcuBCC438AZT6oDg= +github.com/launchdarkly/sdk-meta/api v0.2.0 h1:bBUBGodr52+3ObGOu1tf9CHR/jNh6HcZ3/yYxGPR7JI= +github.com/launchdarkly/sdk-meta/api v0.2.0/go.mod h1:vXfR0z4XBz49IYT/2GDEza+Iat3PcuBCC438AZT6oDg= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= diff --git a/internal/quickstart/choose_sdk.go b/internal/quickstart/choose_sdk.go index 097c21e8..93fcc177 100644 --- a/internal/quickstart/choose_sdk.go +++ b/internal/quickstart/choose_sdk.go @@ -80,33 +80,6 @@ var sdkExamples = map[string]string{ "lua-server-server": "https://github.com/launchdarkly/lua-server-sdk/tree/main/examples/hello-lua-server", } -// sdkOrder is a list of IDs the SDKs in order that they should be rendered based on popularity. -var sdkOrder = []string{ - "react-client-sdk", - "node-server", - "python-server-sdk", - "java-server-sdk", - "dotnet-server-sdk", - "js-client-sdk", - "vue", - "swift-client-sdk", - "go-server-sdk", - "android", - "react-native", - "ruby-server-sdk", - "flutter-client-sdk", - "dotnet-client-sdk", - "erlang-server-sdk", - "rust-server-sdk", - "cpp-client-sdk", - "roku", - "node-client-sdk", - "cpp-server-sdk", - "lua-server-sdk", - "haskell-server-sdk", - "php-server-sdk", -} - // initSDKs is responsible for loading SDK quickstart instructions from the embedded filesystem. // // The names of the files are special: they are the ID of the SDK (e.g. react-native), and are used as an index or @@ -130,15 +103,15 @@ func initSDKs() []sdkDetail { if _, ok := sdkmeta.Names[id]; !ok { continue } - index := slices.Index(sdkOrder, id) - if index == -1 { + popularity, ok := sdkmeta.Popularity[id] + if !ok { // if we missed an SDK don't add it with an invalid index continue } details = append(details, sdkDetail{ id: id, - index: index, + index: popularity - 1, // subtract one since popularity is one-indexed displayName: sdkmeta.Names[id], sdkType: sdkmeta.Types[id], url: sdkExamples[id], diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/base.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/base.yml new file mode 100644 index 00000000..ff8240eb --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/base.yml @@ -0,0 +1,16 @@ +openapi: "3.0.3" +info: + title: Recursive cyclic refs example + version: "1.0" +components: + schemas: + Foo: + properties: + foo2: + $ref: "other.yml#/components/schemas/Foo2" + bar: + $ref: "#/components/schemas/Bar" + Bar: + properties: + foo: + $ref: "#/components/schemas/Foo" diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/other.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/other.yml new file mode 100644 index 00000000..29b72d98 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/circularRef/other.yml @@ -0,0 +1,10 @@ +openapi: "3.0.3" +info: + title: Recursive cyclic refs example + version: "1.0" +components: + schemas: + Foo2: + properties: + id: + type: string diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Bar.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Bar.yml new file mode 100644 index 00000000..cc59fc27 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Bar.yml @@ -0,0 +1,2 @@ +type: string +example: bar diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Cat.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Cat.yml new file mode 100644 index 00000000..c476aa1a --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Cat.yml @@ -0,0 +1,4 @@ +type: object +properties: + cat: + $ref: ../openapi.yml#/components/schemas/Cat diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo.yml new file mode 100644 index 00000000..53a23366 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo.yml @@ -0,0 +1,4 @@ +type: object +properties: + bar: + $ref: ../openapi.yml#/components/schemas/Bar diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo/Foo2.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo/Foo2.yml new file mode 100644 index 00000000..aeac81f4 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/Foo/Foo2.yml @@ -0,0 +1,4 @@ +type: object +properties: + foo: + $ref: ../../openapi.yml#/components/schemas/Foo diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/models/error.yaml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/models/error.yaml new file mode 100644 index 00000000..b4d40479 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/components/models/error.yaml @@ -0,0 +1,2 @@ +type: object +title: ErrorDetails diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/issue615.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/issue615.yml new file mode 100644 index 00000000..d1370e32 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/issue615.yml @@ -0,0 +1,60 @@ +openapi: "3.0.3" +info: + title: Deep recursive cyclic refs example + version: "1.0" +paths: + /foo: + $ref: ./paths/foo.yml +components: + schemas: + FilterColumnIncludes: + type: object + properties: + $includes: + $ref: '#/components/schemas/FilterPredicate' + additionalProperties: false + maxProperties: 1 + minProperties: 1 + FilterPredicate: + oneOf: + - $ref: '#/components/schemas/FilterValue' + - type: array + items: + $ref: '#/components/schemas/FilterPredicate' + minLength: 1 + - $ref: '#/components/schemas/FilterPredicateOp' + - $ref: '#/components/schemas/FilterPredicateRangeOp' + FilterPredicateOp: + type: object + properties: + $any: + oneOf: + - type: array + items: + $ref: '#/components/schemas/FilterPredicate' + $none: + oneOf: + - $ref: '#/components/schemas/FilterPredicate' + - type: array + items: + $ref: '#/components/schemas/FilterPredicate' + additionalProperties: false + maxProperties: 1 + minProperties: 1 + FilterPredicateRangeOp: + type: object + properties: + $lt: + $ref: '#/components/schemas/FilterRangeValue' + additionalProperties: false + maxProperties: 2 + minProperties: 2 + FilterRangeValue: + oneOf: + - type: number + - type: string + FilterValue: + oneOf: + - type: number + - type: string + - type: boolean \ No newline at end of file diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml new file mode 100644 index 00000000..9f884c71 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml @@ -0,0 +1,33 @@ +openapi: "3.0.3" +info: + title: Recursive refs example + version: "1.0" +paths: + /foo: + $ref: ./paths/foo.yml + /double-ref-foo: + get: + summary: Double ref response + description: Reference response with double reference. + responses: + "400": + $ref: "#/components/responses/400" +components: + schemas: + Foo: + $ref: ./components/Foo.yml + Foo2: + $ref: ./components/Foo/Foo2.yml + Bar: + $ref: ./components/Bar.yml + Cat: + $ref: ./components/Cat.yml + Error: + $ref: ./components/models/error.yaml + responses: + "400": + description: 400 Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml.internalized.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml.internalized.yml new file mode 100644 index 00000000..0d508527 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/openapi.yml.internalized.yml @@ -0,0 +1,110 @@ +{ + "components": { + "parameters": { + "number": { + "in": "query", + "name": "someNumber", + "schema": { + "type": "string" + } + } + }, + "responses": { + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "400 Bad Request" + } + }, + "schemas": { + "Bar": { + "example": "bar", + "type": "string" + }, + "Error":{ + "title":"ErrorDetails", + "type":"object" + }, + "Foo": { + "properties": { + "bar": { + "$ref": "#/components/schemas/Bar" + } + }, + "type": "object" + }, + "Foo2": { + "properties": { + "foo": { + "$ref": "#/components/schemas/Foo" + } + }, + "type": "object" + }, + "error":{ + "title":"ErrorDetails", + "type":"object" + }, + "Cat": { + "properties": { + "cat": { + "$ref": "#/components/schemas/Cat" + } + }, + "type": "object" + } + } + }, + "info": { + "title": "Recursive refs example", + "version": "1.0" + }, + "openapi": "3.0.3", + "paths": { + "/double-ref-foo": { + "get": { + "description": "Reference response with double reference.", + "responses": { + "400": { + "$ref": "#/components/responses/400" + } + }, + "summary": "Double ref response" + } + }, + "/foo": { + "get": { + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "properties": { + "foo2": { + "$ref": "#/components/schemas/Foo2" + } + }, + "type": "object" + } + } + }, + "description": "OK" + }, + "400": { + "$ref": "#/components/responses/400" + } + } + }, + "parameters": [ + { + "$ref": "#/components/parameters/number" + } + ] + } + } +} diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/parameters/number.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/parameters/number.yml new file mode 100644 index 00000000..29f0f264 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/parameters/number.yml @@ -0,0 +1,4 @@ +name: someNumber +in: query +schema: + type: string diff --git a/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/paths/foo.yml b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/paths/foo.yml new file mode 100644 index 00000000..4c845b53 --- /dev/null +++ b/vendor/github.com/getkin/kin-openapi/openapi3/testdata/recursiveRef/paths/foo.yml @@ -0,0 +1,15 @@ +parameters: + - $ref: ../parameters/number.yml +get: + responses: + "200": + description: OK + content: + application/json: + schema: + type: object + properties: + foo2: + $ref: ../openapi.yml#/components/schemas/Foo2 + "400": + $ref: "../openapi.yml#/components/responses/400" diff --git a/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/popularity.json b/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/popularity.json new file mode 100644 index 00000000..cb08167f --- /dev/null +++ b/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/popularity.json @@ -0,0 +1,25 @@ +{ + "android": 10, + "cpp-client-sdk": 17, + "cpp-server-sdk": 20, + "dotnet-client-sdk": 14, + "dotnet-server-sdk": 5, + "erlang-server-sdk": 15, + "flutter-client-sdk": 13, + "go-server-sdk": 9, + "haskell-server-sdk": 22, + "java-server-sdk": 4, + "js-client-sdk": 6, + "lua-server-sdk": 21, + "node-client-sdk": 19, + "node-server": 2, + "php-server-sdk": 23, + "python-server-sdk": 3, + "react-client-sdk": 1, + "react-native": 11, + "roku": 18, + "ruby-server-sdk": 12, + "rust-server-sdk": 16, + "swift-client-sdk": 8, + "vue": 7 +} diff --git a/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/releases.json b/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/releases.json index 3cf85160..20c91b8d 100644 --- a/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/releases.json +++ b/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/data/releases.json @@ -3438,11 +3438,17 @@ } ], "swift-client-sdk": [ + { + "major": 9, + "minor": 10, + "date": "2024-08-07T20:59:31Z", + "eol": null + }, { "major": 9, "minor": 9, "date": "2024-08-02T21:47:02Z", - "eol": null + "eol": "2025-08-07T00:00:00Z" }, { "major": 9, diff --git a/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/sdkmeta.go b/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/sdkmeta.go index a8a90a87..0f9f1455 100644 --- a/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/sdkmeta.go +++ b/vendor/github.com/launchdarkly/sdk-meta/api/sdkmeta/sdkmeta.go @@ -31,6 +31,12 @@ var languagesJSON []byte // Languages is a map of SDK IDs to supported languages. var Languages map[string][]string +//go:embed data/popularity.json +var popularityJSON []byte + +// Popularity is a map of SDK IDs to popularity scores. +var Popularity map[string]int + //go:embed data/types.json var typesJSON []byte @@ -112,4 +118,5 @@ func init() { panicOnError(json.Unmarshal(languagesJSON, &Languages)) panicOnError(json.Unmarshal(typesJSON, &Types)) panicOnError(json.Unmarshal(releasesJSON, &Releases)) + panicOnError(json.Unmarshal(popularityJSON, &Popularity)) } diff --git a/vendor/modules.txt b/vendor/modules.txt index bb3cd60a..bc8f98d1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -123,7 +123,7 @@ github.com/josharian/intern # github.com/launchdarkly/api-client-go/v14 v14.0.0 ## explicit; go 1.13 github.com/launchdarkly/api-client-go/v14 -# github.com/launchdarkly/sdk-meta/api v0.1.1 +# github.com/launchdarkly/sdk-meta/api v0.2.0 ## explicit; go 1.20 github.com/launchdarkly/sdk-meta/api/sdkmeta # github.com/lucasb-eyer/go-colorful v1.2.0