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

The OData stuff is missing things to generated a good OData api #24

Closed
paule96 opened this issue May 2, 2022 · 0 comments · Fixed by #25
Closed

The OData stuff is missing things to generated a good OData api #24

paule96 opened this issue May 2, 2022 · 0 comments · Fixed by #25
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@paule96
Copy link
Contributor

paule96 commented May 2, 2022

Describe the bug

The metadata model for the odata endpoints only contains a single namespace. (your assembly namespace as name)
And this namespace don't include a EntityContainer.
For me for example it looks like that:

<?xml version="1.0" encoding="utf-8"?>
  <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:DataServices>
      <Schema Namespace="dynamicapi" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <EntityType Name="WeatherForecast">
          <Key>
            <PropertyRef Name="Id" />
          </Key>
          <Property Name="Date" Type="Edm.DateTimeOffset" Nullable="false" />
          <Property Name="TemperatureC" Type="Edm.Int32" Nullable="false" />
          <Property Name="Summary" Type="Edm.String" />
          <Property Name="Id" Type="Edm.Int32" Nullable="false" />
        </EntityType>
      </Schema>
      <Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <EntityContainer Name="Container" />
      </Schema>
    </edmx:DataServices>
  </edmx:Edmx>

The problem is that other software that tries to read the odata metadata model, will always say you API is empty. (for example Excel or PowerBi to call two by the name)

To fix this you must build your OData model with the following code:

Type model = // type of the model that should be added to your EDM model.
var method = typeof(ODataConventionModelBuilder).GetMethod("EntitySet");
method = method.MakeGenericMethod(model);
method.Invoke(odataBuilder, new object[] { model.Name });

after you run the above code for each modeltype you must run the following to publish the EdmModel:

var edmModel = odataBuilder.GetEdmModel();
services.AddSingleton<IEdmModel>(edmModel);

To Reproduce
Steps to reproduce the behavior:

  1. Go to '/odata/$metadata'
  2. Review the XML
  3. It should look like that:
<?xml version="1.0" encoding="utf-8"?>
  <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:DataServices>
      <Schema Namespace="dynamicapi" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <EntityType Name="WeatherForecast">
          <Key>
            <PropertyRef Name="Id" />
          </Key>
          <Property Name="Date" Type="Edm.DateTimeOffset" Nullable="false" />
          <Property Name="TemperatureC" Type="Edm.Int32" Nullable="false" />
          <Property Name="Summary" Type="Edm.String" />
          <Property Name="Id" Type="Edm.Int32" Nullable="false" />
        </EntityType>
      </Schema>
      <Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
        <EntityContainer Name="Container">
             <EntitySet Name="WeatherForecast" EntityType="dynamicapi.WeatherForecast"/>
        </EntityContainer >
      </Schema>
    </edmx:DataServices>
  </edmx:Edmx>
DeeJayTC added a commit that referenced this issue May 3, 2022
#24 add all models also to the API surface
@DeeJayTC DeeJayTC self-assigned this May 3, 2022
@DeeJayTC DeeJayTC added the enhancement New feature or request label May 3, 2022
@DeeJayTC DeeJayTC added this to Needs triage in API Generator Board via automation May 3, 2022
@DeeJayTC DeeJayTC added this to the 0.2 milestone May 3, 2022
@DeeJayTC DeeJayTC moved this from Needs triage to VNext Done in API Generator Board May 3, 2022
@DeeJayTC DeeJayTC closed this as completed May 3, 2022
API Generator Board automation moved this from VNext Done to Released May 3, 2022
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
Development

Successfully merging a pull request may close this issue.

2 participants