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

How to resolve 'Resource types must inherit from Saule.ApiResource' #259

Open
abhalesd opened this issue Oct 19, 2022 · 3 comments
Open

Comments

@abhalesd
Copy link

I have added package reference of saule in my project. But I am not able to resolve this error occurring after that

Resource types must inherit from Saule.ApiResource

Can you please help me in resolving this?

@joukevandermaas
Copy link
Owner

Did you follow the "getting started" guide? It explains what to do: https://joukevandermaas.github.io/saule/content/1-getting-started.html

@abhalesd
Copy link
Author

Hi,
Thanks for replying.
I have followed most of the instructions.

  1. config.ConfigureJsonApi(); is added to WebAPiConfig.cs
  2. Created resource as follow
public class BuidlingApiResources : ApiResource
    {
        BuidlingApiResources() {
            Attribute(nameof(BuildingDto.CompanyCodeId));
            Attribute(nameof(BuildingDto.CompanyCodeCode));
            Attribute(nameof(BuildingDto.CompanyCodeName));
            Attribute(nameof(BuildingDto.AdministrationType));
            Attribute(nameof(BuildingDto.ManagementId));
            Attribute(nameof(BuildingDto.ManagementIdNum));
            Attribute(nameof(BuildingDto.EconomicUnitId));
            Attribute(nameof(BuildingDto.EconomicUnitIdNum));
            Attribute(nameof(BuildingDto.EconomicUnitName));
            Attribute(nameof(BuildingDto.BuildingId));
        }
    }
  1. Trying to use it like this
[HttpGet]
        [Route("buildings")]
        [Paginated(PerPage = 25, PageSizeLimit = 100)]
        [ReturnsResource(typeof(BuidlingApiResources))]
        public IHttpActionResult GetBuildings([FromUri] string apiKey)
        {
            var messages = new Messages();
            if (string.IsNullOrWhiteSpace(apiKey))
            {
                messages.AddValidationError("The api key is missing.");
            }
            
            if (messages.HasErrors)
            {
                return ApiControllerTools.BadRequestWithErrors(this, messages);
            }
            
            var result = BtsService.GetBuildings(apiKey, messages);
            
            if (messages.HasErrors)
            {
                return ApiControllerTools.BadRequestWithErrors(this, messages);
            }
            
            return Ok(result);
        }
        

@joukevandermaas
Copy link
Owner

I believe the issue may be that you are returning IHttpActionResult. I don't remember if that is supported or not. But if this is a new project I recommend using .net 6 with ASP core and not 4.x with ASP Web API.

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

No branches or pull requests

2 participants