Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching schema by url in library #34

Merged
merged 32 commits into from
Feb 7, 2019
Merged

Fetching schema by url in library #34

merged 32 commits into from
Feb 7, 2019

Conversation

magicmatatjahu
Copy link
Member

Description

Changes proposed in this pull request:

  • Add feature to fetch schema from external resources in library package

Related issue(s)
Resolves #32

magicmatatjahu and others added 29 commits November 8, 2018 12:49
@magicmatatjahu magicmatatjahu added the enhancement New feature or request label Jan 31, 2019
@magicmatatjahu magicmatatjahu added area/library Related to all activities around Library package area/documentation Related to all activities around documentation labels Jan 31, 2019
Copy link
Member

@fmvilas fmvilas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great stuff. I just left some comments. Keep up the great work 🙌

README.md Outdated
@@ -45,6 +49,8 @@ The list of props for the AsyncApi React component includes:

> **NOTE:** The `Partial<T>` type means that every field in the `T` type is optional.

> **NOTE:** You must pass `schema` or `urlSchema` to component for correct work of component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about rewriting this copy?

Either schema or urlSchema prop must be present.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazydek must check this, but thank you for your proposition :)

@@ -98,6 +121,8 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> {

if (!(validatedSchema && validated)) return null;

console.log(validatedSchema);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it forgotten here?

Copy link
Member Author

@magicmatatjahu magicmatatjahu Jan 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah :D I always forget about console.logs in my code. Thanks!

@@ -53,12 +60,28 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> {
}

async componentWillMount() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up componentWillMount is deprecated. Check out: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

componentWillMount and other will be deprecated on >= 17.0 versions. We use at the moment 16.6.3 version of React and we don't see any warnings related to the use of these lifecycles, but I will think whether to change it now or in the next PR.

@@ -16,7 +22,8 @@ import ErrorComponent from '../Error/Error';
import { AsyncApiWrapper } from './styled';

export interface AsyncApiProps {
schema: string | Object;
schema?: string | Object;
urlSchema?: FetchingSchemaInterface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we enforce that either schema or urlSchema must be provided? I know it's possible with prop-types, but not sure about Typescript.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is possible by use type schema: string | Object | FetchingSchemaInterface. If developer pass FetchingSchemaInterface then we will fetch schema from url, otherwise we use schema :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't explain myself correctly. I mean having both schema and urlSchema, like it's right now, but enforcing in the code the rule of having just one of them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented my proposition from second comment in this thread. Please see: https://github.com/asyncapi/asyncapi-react/pull/34/files#diff-2fa873daa631d9246738398633704fd9R25

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I love this solution. Just one question: I see it says string | Object | FetchSchemaInterface, will it always fallback into Object? Saying because an object of the form FetchSchemaInterface is also an object, right? Or will typescript take care of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :) You can pass schema as string (json or yaml), or Object (this is reference to AsyncAPIInterface) or FetchSchemaInterface. I agree with you that FetchSchemaInterface is also a Object, but Object with appropriate fields, so if dev pass Object as FetchSchemaInterface to component then component will execute whole code as FetchSchemaInterface, if pass as Object, then code validate this Object as AsyncApi and show errors if this spec is invalid :) You have to look at it in terms of static typing, not dynamic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Thanks! :)

Copy link
Contributor

@pkosiec pkosiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

README.md Outdated

The `schema` property is required and contains AsyncAPI specification. It should be one of the `string` or [`AsyncApiInterface`](./library/src/types.ts#L13) type. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification).
The `schema` property is required and contains AsyncAPI specification. It should be one of the `string` or [`AsyncApiInterface`](./library/src/types.ts#L13) type or [`FetchingSchemaInterface`](./library/src/helpers/fetchSchema.ts#L1) object for fetching schema from external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `schema` property is required and contains AsyncAPI specification. It should be one of the `string` or [`AsyncApiInterface`](./library/src/types.ts#L13) type or [`FetchingSchemaInterface`](./library/src/helpers/fetchSchema.ts#L1) object for fetching schema from external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification).
The `schema` property is required and contains AsyncAPI specification. Use the `string` type, the [`AsyncApiInterface`](./library/src/types.ts#L13) type, or the [`FetchingSchemaInterface`](./library/src/helpers/fetchSchema.ts#L1) object to fetch the schema from an external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification).

@magicmatatjahu magicmatatjahu merged commit f625e3a into asyncapi:master Feb 7, 2019
@magicmatatjahu magicmatatjahu deleted the fetching-schema-by-url branch February 7, 2019 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Related to all activities around documentation area/library Related to all activities around Library package enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants