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

Cannot use parent class in client #21

Closed
kevinvenclovas opened this issue Apr 24, 2020 · 12 comments
Closed

Cannot use parent class in client #21

kevinvenclovas opened this issue Apr 24, 2020 · 12 comments
Labels
question Further information is requested

Comments

@kevinvenclovas
Copy link

kevinvenclovas commented Apr 24, 2020

Hi,

i have two classes both with the same parent class


CLASSES
public class MailMessageSmtpData : MailData
{
     public int SmtpPort { get; set; }
}

public class MailMessageSendGridData : MailData
{
     public int ApiKey{ get; set; }
}

public class MailData
{
     public string Subject { get; set; }
}

CONTROLLER

[HttpPost]
[Route("mail/smtp")]
[ProducesResponseType(typeof(MailMessage), 200)]
public async Task<IActionResult> SendSmtpMail([FromBody] MailMessageSmtpData m)
{
     return Ok(await new MailMessageService().SendMailWithSmtp(m));
}

[HttpPost]
[Route("mail/sendgrid")]
[ProducesResponseType(typeof(MailMessage), 200)]
public async Task<IActionResult> SendSendGridMail([FromBody]  MailMessageSendGridData m)
{
     return Ok(await new MailMessageService().SendMailWithSendGrid(m));
}



CLIENT CODE

-> MailData Class did not exist
 private MailData data= new MailData(); 

My problem here is that i can't instantiate an object from type MailData in my client code.
Can't find the MailData class in the generated code.

How can i solve this issue?

@kevinvenclovas kevinvenclovas changed the title use parent class in client Cannot use parent class in client Apr 24, 2020
@unchase
Copy link
Owner

unchase commented Apr 25, 2020

Hi, @Kshopper93
What error does the IDE show you?
Can you attach the screenshot?

@kevinvenclovas
Copy link
Author

kevinvenclovas commented Apr 25, 2020

Class not found.

image

image

@kevinvenclovas
Copy link
Author

Hello,

do you found any issue in my code?

@unchase
Copy link
Owner

unchase commented Apr 27, 2020

Hi, @Kshopper93

Please, attach a screenshot of the generated MailData class.
Or send me the specification file by which the code was generated (to spiritkola@hotmail.com directly).

@kevinvenclovas
Copy link
Author

kevinvenclovas commented Apr 27, 2020

Hi, @unchase

there is no MailData class in the generated file. I have only the Child classes MailMessageSmtPData and MailMessageSendGridData.
The MailData (Parent class) variables merged into the child chlasses. But i need the Base and Child classes separately

image

Where can i find the specification file?

@unchase
Copy link
Owner

unchase commented Apr 27, 2020

You can find this file in the directory with the generated client (it has the extension - json):

spec

@kevinvenclovas
Copy link
Author

@unchase - U got a Email with the File.

Thank you

@unchase
Copy link
Owner

unchase commented Apr 27, 2020

@Kshopper93
There is no MailMessage contract in json-specification file (there is only MailMessageSmtpData and MailMessageSendGridData), therefore, it is not created in client code.

Should to look the issue on the server side, which generates the specification, because the connected service generates a client based on the specification passed to it.

@kevinvenclovas
Copy link
Author

@unchase
Can I send you the full Project and you can take a look?

@unchase
Copy link
Owner

unchase commented Apr 27, 2020

Of course, send, I will try to help.

@kevinvenclovas
Copy link
Author

@unchase

U got a email with github link to my project.

Thank you.

@unchase
Copy link
Owner

unchase commented Apr 27, 2020

@Kshopper93
See the same issue. There is a problem in specification generation: generates without base classes.
it's not implemented yet in Swashbuckle.AspNetCore.

You can try to use NSwag in the server side for generating specification. It seems to be allows to generate base classes in the specification schema: see this and this topics.

@unchase unchase closed this as completed May 3, 2020
@unchase unchase added the question Further information is requested label Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants