Skip to content

Commit

Permalink
Added parsing of files only when kind is 'Endpoint'
Browse files Browse the repository at this point in the history
  • Loading branch information
metamemelord committed Sep 26, 2021
1 parent 3049a44 commit 416cf9e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions boilerplate/spec/hello/root.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: mocks/v1
kind: MockEndpoint
apiVersion: apps/v1
kind: Endpoint
spec:
requests:
- description: I serve the path /hello
Expand Down
4 changes: 2 additions & 2 deletions boilerplate/spec/hello/world.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: mocks/v1
kind: MockEndpoint
apiVersion: apps/v1
kind: Endpoint
spec:
requests:
- description: Serve static files by providing paths!
Expand Down
6 changes: 3 additions & 3 deletions boilerplate/spec/root.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: mocks/v1
kind: MockEndpoint
apiVersion: apps/v1
kind: Endpoint
spec:
requests:
- description: Returning the homepage of Mockerino
Expand All @@ -12,4 +12,4 @@ spec:
Hello! Welcome to Mockerino!<br>Click <a href="/hello">here</a> to see how root.yaml serves the path root.
- description: A post request which says "OK"
method: POST
raw_body: OK
raw_body: OK
4 changes: 4 additions & 0 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ impl Endpoint {
pub fn request(&self) -> &Vec<Request> {
&self.spec.requests
}

pub fn kind(&self) -> String {
self.kind.clone()
}
}
25 changes: 15 additions & 10 deletions src/spec_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ fn process_file(

let endpoint = parse_yaml_file(path)?;

// Handle dynamic routes here
if path_param_regex.find(request_path.as_ref()).is_some() {
// TODO: Add capability to use dynamic routes.
process_dynamic_path(endpoint, request_path.as_ref())
} else {
Ok(endpoint
.request()
.iter()
.map(|req| RequestWithMetadata::new(req.clone(), request_path.to_string()))
.collect())
match endpoint.kind().as_ref() {
"Endpoint" => {
// Handle dynamic routes here
if path_param_regex.find(request_path.as_ref()).is_some() {
// TODO: Add capability to use dynamic routes.
process_dynamic_path(endpoint, request_path.as_ref())
} else {
Ok(endpoint
.request()
.iter()
.map(|req| RequestWithMetadata::new(req.clone(), request_path.to_string()))
.collect())
}
}
_ => Err(anyhow::Error::msg("Unsupported 'kind' in spec file")),
}
}

Expand Down

0 comments on commit 416cf9e

Please sign in to comment.