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

SwagGen and update to LoadFromFile #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rjmatthews62
Copy link

I have been working on a generator to create Delphi objects to consume and produce JSON payloads.

Whether or not you choose to include SwagGen in your main branch, you might want to cherry pick changes I made to the TSwagDoc.LoadFromFile, in that it is:

  • More tolerant of missing swagger sections or values
  • Now populates Definitions.

On a related note, are you planning at any time to refactor JSON.Commom.Helpers to JSON.Common.Helpers?

Anyway, thanks for making this project available.

Made TSwagDoc.LoadFromFile more relaxed about missing sections. Added code to include definitions in the LoadFromFile
@marcelojaloto
Copy link
Owner

marcelojaloto commented Aug 27, 2018

Hi @rjmatthews62,
I'm working on new module to complement a pending part in SwagDoc. In the coming weeks I'll be making a Json Schema creator available so that you no longer need to manually generate the Json in a request or response definition.
This new module will need to add more code in the JSON.Common.Helpers unit.
I am very happy and grateful to be collaborating with the SwagDoc project. Your idea is very interesting but I would like you to refine to a set of classes with well defined methods and attributes to develop Swag.Gen. What do you think about it?
I would also like you to note the SwagDoc code pattern, okay?

@marcelojaloto
Copy link
Owner

marcelojaloto commented Aug 27, 2018

@rjmatthews62
On the improvement in TJSONValueHelper I have analyzed the TJSONValue class and have a very similar behavior between GetValueRelaxed and GetValue. So that there is no confusion what do you think of the proposal below?

type
  TJSONValueHelper = class helper for TJSONValue
  public
    function GetValue<T>(const pPath: string; const pConsiderDefault: Boolean): T; overload;
    function TryGetValue<T>(const pPath: string): T; overload;
    function TryGetValue<T>(const pPath: string; pDefault: T): T; overload;
  end;

implementation

{ TJSONValueHelper }

function TJSONValueHelper.GetValue<T>(const pPath: string; const pConsiderDefault: Boolean): T;
begin
  if pConsiderDefault then
    Result := GetValue<T>(pPath, Default(T))
  else
    Result := GetValue<T>(pPath);
end;

function TJSONValueHelper.TryGetValue<T>(const pPath: string): T;
begin
  Result := TryGetValue<T>(pPath, Default(T));
end;

function TJSONValueHelper.TryGetValue<T>(const pPath: string; pDefault: T): T;
begin
  result := TryGetValue<T>(pPath, pDefault);
end;

@marcelojaloto
Copy link
Owner

@rjmatthews62,
About the changes in TSwagDoc.LoadFromFile I really liked it and will certainly be added in the main branch.

@marcelojaloto
Copy link
Owner

@rjmatthews62,
Congratulations on all your collaborations with the SwagDoc project.

@rjmatthews62
Copy link
Author

Re: TryGetValue, doesn't that end up calling itself? In that, isn't there already a TryGetValue in the main class? I must admit, helper classes are a feature I only just found (and I've been programming in Delphi for decades...!) so there may be some subtleties I missed.
SwagGen was written in a hurry because I needed it, so I'm happy to discuss refactoring it so it is more inline with your coding standards. Anything in particular you wanted changed?

@marcelojaloto
Copy link
Owner

@rjmatthews62 TryGetValue in my proposal is overloaded and is calling another overload of itself passing different parameters.

About SwagGen I would like it to be done with well-defined classes. Try to observe the SwagDoc code patterns such as class names, variables, spacing, indentations, methods, and more.

Do you want to try to improve and send me an update of this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants