Skip to content

Commit

Permalink
[ENG-981] Generate Python,TypeScript SDKs and test SDKs for Sportmonks (
Browse files Browse the repository at this point in the history
konfig-dev#74)

* requestBeforeUrlHook + optionalParameters + index.test.ts

* response descriptions arent that important—so skip by default

* handle api key authorization in p2o

* test_simple.py for Python SDK

* add clientState to generated documentation

* add os import by default in test_simple

* update openapi.yaml

* add pprint as default import in test_simple.py

* transform inner schemas

* useDictionaryBasedTypedDict

* useDictionaryBasedTypedDict

* typo

* request_before_url_hook

* fix typo in typescript sdk

* SimpleTest.mustache for PHP SDK

* SimpleTest.mustache

* use upper for httpMethod in Python SDK

* api_key_name.mustache

* fix NPE error

* settings.json for PHP for increased max file size

* settings.json for PHP SDK

* client.mustache + ApiClientCustom.mustache

* clientStateSetterGetterPascalCase

* clientNAme

* csharpier

* C# template updates

* x-konfig-null-placeholder

* allPoisoned

* clientStateWithExamples

* update sportmonks-sdks
  • Loading branch information
dphuang2 authored Jul 19, 2023
1 parent d6b625c commit 7d5d6f6
Show file tree
Hide file tree
Showing 60 changed files with 107,952 additions and 106,251 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"rebornix.ruby",
"vscjava.vscode-java-test",
"redhat.vscode-yaml",
"wingrunr21.vscode-ruby"
"wingrunr21.vscode-ruby",
"csharpier.csharpier-vscode"
]
}
2 changes: 1 addition & 1 deletion customers/sportmonks/sportmonks-sdks
Submodule sportmonks-sdks updated 8512 files
7 changes: 7 additions & 0 deletions generator/konfig-dash/api/src/functions/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export const myHandler = async (event: APIGatewayEvent, context: Context) => {
gitRepoName: generatorConfig.git.repoName,
moduleName: generatorConfig.moduleName,
clientState: generatorConfig.clientState,
clientStateWithExamples: generatorConfig.clientStateWithExamples,
tagPriority: body.tagPriority,
},
artifactVersion: generatorConfig.version,
Expand Down Expand Up @@ -345,6 +346,7 @@ export const myHandler = async (event: APIGatewayEvent, context: Context) => {
userAgent: generatorConfig.userAgent,
gitRepoName: generatorConfig.git.repoName,
clientState: generatorConfig.clientState,
clientStateWithExamples: generatorConfig.clientStateWithExamples,
supportPhp7: generatorConfig.supportPhp7,
},
packageName: generatorConfig.packageName,
Expand Down Expand Up @@ -419,6 +421,7 @@ export const myHandler = async (event: APIGatewayEvent, context: Context) => {
invokerPackage: packageName,
clientName: generatorConfig.clientName,
clientState: generatorConfig.clientState,
clientStateWithExamples: generatorConfig.clientStateWithExamples,
apiDocumentationAuthenticationPartial:
generatorConfig.apiDocumentationAuthenticationPartial,
removeKonfigBranding: generatorConfig.removeKonfigBranding,
Expand Down Expand Up @@ -497,6 +500,7 @@ export const myHandler = async (event: APIGatewayEvent, context: Context) => {
additionalProperties: {
omitInfoDescription: body.omitInfoDescription,
tagPriority: body.tagPriority,
clientName: generatorConfig.clientName,
packageVersion: generatorConfig.version,
readmeSnippet: generatorConfig.readmeSnippet,
readmeSupportingDescriptionSnippet:
Expand All @@ -507,6 +511,7 @@ export const myHandler = async (event: APIGatewayEvent, context: Context) => {
defaultTimeout: generatorConfig.defaultTimeout,
userAgent: generatorConfig.userAgent,
clientState: generatorConfig.clientState,
clientStateWithExamples: generatorConfig.clientStateWithExamples,
},
generatorName: 'csharp-netcore',
packageName: generatorConfig.packageName,
Expand Down Expand Up @@ -554,6 +559,7 @@ export const myHandler = async (event: APIGatewayEvent, context: Context) => {
keepAllParametersOptional: generatorConfig.keepAllParametersOptional,
clientName: generatorConfig.clientName,
clientState: generatorConfig.clientState,
clientStateWithExamples: generatorConfig.clientStateWithExamples,
apiKeyAlias: generatorConfig.apiKeyAlias,
packageUrl: generatorConfig.packageUrl,
apiDocumentationAuthenticationPartial:
Expand Down Expand Up @@ -734,6 +740,7 @@ async function queueTypeScriptGeneration({
apiDocumentationAuthenticationPartial:
generatorConfig.apiDocumentationAuthenticationPartial,
clientState: generatorConfig.clientState,
clientStateWithExamples: generatorConfig.clientStateWithExamples,
defaultTimeout: generatorConfig.defaultTimeout,
userAgent: generatorConfig.userAgent,
includeFetchAdapter: generatorConfig.includeFetchAdapter,
Expand Down
2 changes: 2 additions & 0 deletions generator/konfig-dash/packages/konfig-cli/src/commands/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export default class Fix extends Command {
}),
skipMissingResponseDescriptionFix: Flags.boolean({
name: 'skip missing response description fix',
default: true,
allowNo: true,
description: 'Ignores fixing a missing description in response schema',
}),
skipListUsageSecurity: Flags.boolean({
Expand Down
11 changes: 10 additions & 1 deletion generator/konfig-dash/packages/konfig-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ export default class Init extends Command {
mergeWithExistingObjectAndWrite({
path: fromVscodeFolder('extensions.json'),
json: {
recommendations: ['stoplight.spectral', 'redhat.vscode-yaml'],
recommendations: [
'stoplight.spectral',
'redhat.vscode-yaml',
'csharpier.csharpier-vscode',
],
},
})
CliUx.ux.action.stop()
Expand Down Expand Up @@ -211,6 +215,10 @@ export default class Init extends Command {
},
},
'ruby.format': 'rubocop', // use rubocop for formatting
'[csharp]': {
'editor.formatOnSave': true,
'editor.defaultFormatter': 'csharpier.csharpier-vscode',
},
},
})
CliUx.ux.action.stop()
Expand Down Expand Up @@ -383,6 +391,7 @@ export default class Init extends Command {
packageName: `${camelcase(answers.sdkName, {
pascalCase: true,
})}.Net`,
clientName: camelcase(answers.sdkName, { pascalCase: true }),
outputDirectory: 'csharp',
logoPath: answers.logoPath,
git: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { z } from './zod'

import { TemplateFiles } from './TemplateFiles'
import { topLevelOperationsOrderedSchema } from './KonfigYaml'
import {
clientStateWithExamples,
topLevelOperationsOrderedSchema,
} from './KonfigYaml'
import { tagPrioritySchema } from './KonfigYamlCommon'

const additionalProperties = z.object({
Expand All @@ -19,6 +22,7 @@ const additionalProperties = z.object({
useSecurityKeyParamNameAsPropertyName: z.boolean().optional(),
objectPropertyNamingConvention: z.string().optional(),
clientState: z.string().array().optional(),
clientStateWithExamples,
clientStateIsOptional: z.boolean().optional(),
modelPackage: z.string().optional(),
supportPhp7: z.boolean().optional(),
Expand Down
21 changes: 21 additions & 0 deletions generator/konfig-dash/packages/konfig-lib/src/KonfigYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const clientState = z
'A list of stateful properties generated into the SDK that can be used in custom implementation hooks. This is useful when you need state in the SDK that is not described in the OpenAPI Specification such as a key used for request signing.'
)

export const clientStateWithExamples = z
.object({ name: z.string(), example: z.string() })
.array()
.optional()
.describe(
'A list of stateful properties generated into the SDK that can be used in custom implementation hooks. This is useful when you need state in the SDK that is not described in the OpenAPI Specification such as a key used for request signing. This is different from the "clientState" field in that it also includes examples for the generated documentation'
)

const javaGroupId = z
.string()
.describe(
Expand All @@ -26,6 +34,7 @@ export const javaConfig = z.object({
removeKonfigBranding: z.boolean().optional(),
clientName: z.string(),
clientState,
clientStateWithExamples,
toStringReturnsJson: z
.boolean()
.optional()
Expand All @@ -49,6 +58,7 @@ export const rubyConfig = z.object({
moduleName: z.string(),
gemName: z.string(),
clientState,
clientStateWithExamples,
})

export const goConfig = z.object({
Expand All @@ -74,6 +84,13 @@ export const objcConfig = z.object({
})

export const csharpConfig = z.object({
clientName: z
.string()
.refine(
(clientName) =>
clientName.endsWith('Client') ||
`clientName must be suffixed with "Client"`
),
logoPath: z
.string()
.refine((logoPath) => logoPath.endsWith('.png'), {
Expand All @@ -88,6 +105,7 @@ export const csharpConfig = z.object({
'The name of this package that shows up on https://nuget.org (e.g. "Acme.Net")'
),
clientState,
clientStateWithExamples,
})

export const topLevelOperationsOrderedSchema = z
Expand Down Expand Up @@ -120,6 +138,7 @@ export const pythonConfig = z.object({
objectPropertyNamingConvention.default('snake_case'),
clientName: z.string(),
clientState,
clientStateWithExamples,
clientStateIsOptional: z
.boolean()
.describe('Whether or not to raise an error if client state is provided')
Expand Down Expand Up @@ -153,6 +172,7 @@ export const swiftConfig = z.object({
export const phpConfig = z.object({
packageName: z.string().describe('acme-php'),
clientState,
clientStateWithExamples,
supportPhp7: z.boolean().optional().default(false),
packagistUsername: z
.string()
Expand Down Expand Up @@ -183,6 +203,7 @@ export const typescriptConfig = z.object({
objectPropertyNamingConvention:
objectPropertyNamingConvention.default('camelCase'),
clientState,
clientStateWithExamples,
removeRequiredProperties: removeRequiredPropertiesSchema.optional(),
topLevelOperations: topLevelOperationsSchema,
gitlab: z
Expand Down
15 changes: 15 additions & 0 deletions generator/konfig-dash/packages/konfig-lib/src/KonfigYamlCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ export const tagPrioritySchema = z
'Order of tags to be processed by Konfig. This can be used to configure which operation is used when generated the getting started documentation in the generated README for an SDK.'
)

export const optionalParameters = z
.object({
name: z.string().describe(`"name" field of parameter`),
in: z.string().describe(`"in" field of parameter`),
})
.array()
.describe(`Can be configured to make specified parameters optional in the
SDKs. This can be useful if you have a set of parameters you would rather
instantiate on the top-level client to avoid redundant passing of this
parameter. For example if you have a "version" parameter that you repeatedly
pass throughout the operations, you can instead make it optional, add it as a
client state, and implement a request hook to attach the "version" client
state to the operation.`)

export const KonfigYamlCommon = z
.object({
fixConfig: fixConfig.optional(),
Expand All @@ -43,6 +57,7 @@ export const KonfigYamlCommon = z
attachNullabletoAllResponseSchemas: z.boolean().optional(),
validateRequiredPropertiesAndParametersAreNonEmpty: z.boolean().optional(),
stripRequiredStringProperties: z.boolean().optional(),
optionalParameters: optionalParameters.optional(),
doNotValidateGloballyRequiredSecurity: z.boolean().optional(),
infoContactEmail: z.string().optional(),
infoContactName: z.string().optional(),
Expand Down
Loading

0 comments on commit 7d5d6f6

Please sign in to comment.