Skip to content

Commit

Permalink
Merge pull request #7 from Sideko-Inc/mock-server-for-tests
Browse files Browse the repository at this point in the history
Mock server option for tests
  • Loading branch information
pk8189 authored Jul 9, 2024
2 parents 6ff7b49 + a7110bd commit d5ebbb0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sideko"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
authors = [
"Elias Posen <[email protected]>",
Expand Down
5 changes: 5 additions & 0 deletions core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ enum SdkCommands {
#[arg(long, short)]
/// Name of SDK package to generate
package_name: Option<String>,
#[arg(long, short)]
/// URL of Sideko Mock Server for generated testing suite
tests_mock_server_url: Option<String>,
},
}

Expand Down Expand Up @@ -153,6 +156,7 @@ pub async fn cli(args: Vec<String>) -> result::Result<()> {
output,
base_url,
package_name,
tests_mock_server_url,
} => {
// Set defaults
let destination = if let Some(o) = output {
Expand All @@ -171,6 +175,7 @@ pub async fn cli(args: Vec<String>) -> result::Result<()> {
language: language.inner.clone(),
base_url: base_url.clone(),
package_name: package_name.clone(),
tests_mock_server_url: tests_mock_server_url.clone(),
};

if let OpenApiSource::Raw(_) = params.source {
Expand Down
2 changes: 2 additions & 0 deletions core/src/cmds/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct GenerateSdkParams {
// options
pub base_url: Option<String>,
pub package_name: Option<String>,
pub tests_mock_server_url: Option<String>,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -119,6 +120,7 @@ pub async fn handle_generate(params: &GenerateSdkParams) -> Result<()> {
language: params.language.clone(),
package_name: params.package_name.clone(),
base_url: params.base_url.clone(),
tests_mock_server_url: params.tests_mock_server_url.clone(),
},
})
.await
Expand Down
1 change: 1 addition & 0 deletions sideko-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ let response = client
}
),
package_name: Some(serde_json::json!({ "value" : "my_sdk" })),
tests_mock_server_url: Some("http://api.sideko.dev/mock".to_string()),
},
});
```
5 changes: 5 additions & 0 deletions sideko-api/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct StatelessGenerateSdk {
pub openapi: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub package_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tests_mock_server_url: Option<String>,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Default, Clone)]
pub enum ErrorCodeEnum {
Expand All @@ -65,6 +67,8 @@ pub enum ErrorCodeEnum {
InvalidOpenapi,
#[serde(rename = "invalid_url")]
InvalidUrl,
#[serde(rename = "insufficient_features")]
InsufficientFeatures,
}
impl std::fmt::Display for ErrorCodeEnum {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand All @@ -77,6 +81,7 @@ impl std::fmt::Display for ErrorCodeEnum {
ErrorCodeEnum::UnavailableSubdomain => "unavailable_subdomain",
ErrorCodeEnum::InvalidOpenapi => "invalid_openapi",
ErrorCodeEnum::InvalidUrl => "invalid_url",
ErrorCodeEnum::InsufficientFeatures => "insufficient_features",
};
write!(f, "{}", str_val)
}
Expand Down
2 changes: 1 addition & 1 deletion sideko-py/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sideko-py"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
authors = [
"Elias Posen <[email protected]>",
Expand Down
2 changes: 2 additions & 0 deletions sideko-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn generate_sdk(
dest: PathBuf,
base_url: Option<String>,
package_name: Option<String>,
tests_mock_server_url: Option<String>,
) -> PyResult<()> {
utils::init_logger(log::Level::Warn);
config::load_config(config::config_bufs(vec![]));
Expand All @@ -49,6 +50,7 @@ pub fn generate_sdk(
language: language.to_gen_lang(),
base_url,
package_name,
tests_mock_server_url,
};

let cmd_res = tokio::runtime::Runtime::new()
Expand Down
29 changes: 13 additions & 16 deletions sideko_openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ components:
properties:
api_key:
type: string
example:
value: sk_live_1234abcd
example: sk_live_1234abcd

CliUpdate:
type: object
Expand All @@ -202,8 +201,7 @@ components:
$ref: "#/components/schemas/CliUpdateSeverity"
message:
type: string
example:
value: Requires update to 0.2.0 for security patch
example: Requires update to 0.2.0 for security patch

CliUpdateSeverity:
type: string
Expand All @@ -221,21 +219,22 @@ components:
openapi:
type: string
description: OpenAPI content in YAML or JSON format
example:
description: OpenAPI Sample in YAML format
value: "openapi: 3.0.0 info: {title: Sample API, description: 'Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.', version: 0.1.9} servers: [{url: 'http://api.example.com/v1', description: 'Optional server description, e.g. Main (production) server'}, {url: 'http://staging-api.example.com', description: 'Optional server description, e.g. Internal staging server for testing'}] paths: {/users: {get: {summary: 'Returns a list of users.', description: 'Optional extended description in CommonMark or HTML.', responses: {'200': {description: 'A JSON array of user names', content: {application/json: {schema: {type: array, items: {type: string}}}}}}}}}"
example: "openapi: 3.0.0 info: {title: Sample API, description: 'Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.', version: 0.1.9} servers: [{url: 'http://api.example.com/v1', description: 'Optional server description, e.g. Main (production) server'}, {url: 'http://staging-api.example.com', description: 'Optional server description, e.g. Internal staging server for testing'}] paths: {/users: {get: {summary: 'Returns a list of users.', description: 'Optional extended description in CommonMark or HTML.', responses: {'200': {description: 'A JSON array of user names', content: {application/json: {schema: {type: array, items: {type: string}}}}}}}}}"
language:
$ref: "#/components/schemas/GenerationLanguage"
package_name:
type: string
description: Name of the SDK package to be generated
example:
value: my_sdk
example: my_sdk
base_url:
type: string
description: The default base url to be set in the generated SDK
example:
value: http://127.0.0.1:8080/api
example: http://127.0.0.1:8080/api
tests_mock_server_url:
type: string
format: uri
description: If included, the SDK will include a testing suite that can be run against a Sideko mock server. Your account must include mock servers to use this feature.
example: http://api.sideko.dev/mock

GenerationLanguage:
type: string
Expand All @@ -260,6 +259,7 @@ components:
- unavailable_subdomain
- invalid_openapi
- invalid_url
- insufficient_features

Error:
type: object
Expand All @@ -271,8 +271,7 @@ components:
$ref: "#/components/schemas/ErrorCode"
description:
type: string
example:
value: Bad request
example: Bad request

ApiProject:
type: object
Expand Down Expand Up @@ -341,9 +340,7 @@ components:
openapi:
type: string
description: OpenAPI content as a string in JSON format
example:
description: OpenAPI Sample in YAML format
value: "openapi: 3.0.0 info: {title: Sample API, description: 'Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.', version: 0.1.9} servers: [{url: 'http://api.example.com/v1', description: 'Optional server description, e.g. Main (production) server'}, {url: 'http://staging-api.example.com', description: 'Optional server description, e.g. Internal staging server for testing'}] paths: {/users: {get: {summary: 'Returns a list of users.', description: 'Optional extended description in CommonMark or HTML.', responses: {'200': {description: 'A JSON array of user names', content: {application/json: {schema: {type: array, items: {type: string}}}}}}}}}"
example: "openapi: 3.0.0 info: {title: Sample API, description: 'Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.', version: 0.1.9} servers: [{url: 'http://api.example.com/v1', description: 'Optional server description, e.g. Main (production) server'}, {url: 'http://staging-api.example.com', description: 'Optional server description, e.g. Internal staging server for testing'}] paths: {/users: {get: {summary: 'Returns a list of users.', description: 'Optional extended description in CommonMark or HTML.', responses: {'200': {description: 'A JSON array of user names', content: {application/json: {schema: {type: array, items: {type: string}}}}}}}}}"
is_valid:
type: boolean
description: Whether or not your OpenAPI Specification is valid

0 comments on commit d5ebbb0

Please sign in to comment.